tags:

views:

44

answers:

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?

+2  A: 

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();
Roku
`bword:blood transfusion` would work too (assuming the system copes with URNs).
Donal Fellows
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
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