Qt 4.8 QUrl.toLocalFile behavior change, impacts to KUrl (and friends)

Thiago Macieira thiago at kde.org
Sat Oct 29 08:25:03 BST 2011

On Saturday, 29 de October de 2011 04:38:00 Milian Wolff wrote:
> 1) When does it manifest? Apparently when using QUrl("...") directly, if I'm
> not mistaken. But what if we use KUrl?

You're correct: this problem manifests when you use QUrl's constructor 
directly, assuming it will understand a local file path for what it is and not 
parse it is a URL. KUrl's constructor calls fromPathOrUrl, so it will try to 
guess according to some heuristics.

The reason why this behaviour exists in QUrl and why I think KUrl is flawed is 
that there's a category of URLs that are incomplete, the relative URLs, also 
known as URL refs. That's what you see in the "href" or "src" attributes in 
HTML: those are real URL components, but they are partial. They need to be 
resolved against a base URL, usually the document's. 

There's no way to tell apart a local file path from a URL ref and the examples 
I gave show how it would be interpreted differently.

> 2) Is the -D... define to catch this problem at compile time already
> supported  in Qt 4.7?


Note it just makes the constructor explicit: it's meant to catch accidental 
conversions. If you spell out QUrl, it will still get used.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20111029/3315ee45/attachment.sig>

More information about the kde-core-devel mailing list