1
QUrl url("bword://blood transfusion");
QString res = url.toString();

Why I got the string "bword:" instead of "bword://blood transfusion"?

How can I get the string "bword://blood transfusion" form the QUrl?

simpzan
  • 515
  • 6
  • 15

1 Answers1

4

URL syntax can be quite complex, see this Wikipedia article. The problem is that your URL does not contain authority field, it only has scheme field "bword" and path "//blood transfusion". And according to the RFC3986 - Uniform Resource Identifier (URI): Generic Syntax:

When authority is not present, the path cannot begin with two slash characters ("//").

So your URL is not valid (although isValid() returns true). Change your code to:

QUrl url("bword:/blood transfusion");
QString res = url.toString();
  • 1
    `bword:blood transfusion` would work too (assuming the system copes with URNs). – Donal Fellows Sep 13 '10 at 15:41
  • indeed, http:/foo bar works, so does http://foobar . The bug in QUrl seems to be that it partially parses urls - IMO it should just create an completely empty, invalid object (QUrl::isValid() == false) when parsing fails. – Frank Osterfeld Sep 13 '10 at 17:49
  • Thank you for your solution. The url I got is from data file from stardict dictionary file. maybe I can only rebuild the dictionary to change the url. – simpzan Sep 15 '10 at 12:01