PDA

View Full Version : Problem with QDesktopServices



innerhippy
15th November 2008, 15:50
Greetings

It seems that QDesktopServices is having problems launching urls and does some incorrect sanitizing of the url.
The following 2 calls should give the same results:


QUrl url ("http://www.example.com/longpathwith%3Dcharacters");

system(qPrintable(QString("firefox http://%1%2").arg(url.host()).arg(url.path())));
QDesktopServices::openUrl(url);


The system call works fine, launching firefox successfully.
The call to QDesktopServices launches firefox with an invalid url. The address bar indicates that "%3D" has been replaced with "%253D".

The documentation states:

Any occurrences of a percent character "%" not followed by exactly two hexadecimal characters (e.g., "13% coverage.html") will be replaced by "%25".
Which would suggest that %3D should work.

Any idea what's going on - a bugette perhaps?

wysota
15th November 2008, 22:52
Where does the documentation say so? In QDesktopServices or QUrl?

innerhippy
16th November 2008, 10:21
In QUrl, under "enum QUrl::ParsingMode"

I've tried using both QUrl::TolerantMode and QUrl::StrictMode modes, but no joy.

wysota
16th November 2008, 10:37
Maybe the fault lies on the side of the desktop services class and not the url? It might not give you such guarantees.

innerhippy
16th November 2008, 13:42
I agree - the thread name says it all..
If the url is not malformed, then QDesktopServices shouldn't be making any changes.

The final call to launch the app seems to be (from src/gui/util/qdesktopservices_x11.cpp)

return (QProcess::startDetached(client + " " + url.toEncoded()));

Could this be the problem?

Thanks for your help - much appreciated.

wysota
16th November 2008, 13:46
I suggest you decode the percentage notation before sending the request to desktop services. Filing a bug report to Qt Software might be a good thing to do as well.

innerhippy
18th November 2008, 20:14
Thanks - it works now

Just in case anyone else has the same problem:


QByteArray data = model()->data(currentIndex(),Qt::UserRole).toByteArray();
QUrl url = QUrl::fromEncoded(data);

if (url.isValid())
QDesktopServices::openUrl(url);