Results 1 to 7 of 7

Thread: Problem with QDesktopServices

  1. #1
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem with QDesktopServices

    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:
    Qt Code:
    1. QUrl url ("http://www.example.com/longpathwith%3Dcharacters");
    2.  
    3. system(qPrintable(QString("firefox http://%1%2").arg(url.host()).arg(url.path())));
    4. QDesktopServices::openUrl(url);
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QDesktopServices

    Where does the documentation say so? In QDesktopServices or QUrl?

  3. #3
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QDesktopServices

    In QUrl, under "enum QUrl::ParsingMode"

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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QDesktopServices

    Maybe the fault lies on the side of the desktop services class and not the url? It might not give you such guarantees.

  5. #5
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with QDesktopServices

    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)
    Qt Code:
    1. return (QProcess::startDetached(client + " " + url.toEncoded()));
    To copy to clipboard, switch view to plain text mode 

    Could this be the problem?

    Thanks for your help - much appreciated.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with QDesktopServices

    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.

  7. #7
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: Problem with QDesktopServices

    Thanks - it works now

    Just in case anyone else has the same problem:
    Qt Code:
    1. QByteArray data = model()->data(currentIndex(),Qt::UserRole).toByteArray();
    2. QUrl url = QUrl::fromEncoded(data);
    3.  
    4. if (url.isValid())
    5. QDesktopServices::openUrl(url);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.