Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDesktopServices::openUrl() drops query string from URL...
Forum Updated to NodeBB v4.3 + New Features

QDesktopServices::openUrl() drops query string from URL...

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MauriceCat
    wrote on last edited by
    #1

    Greetings,

    I'm using the following code to try and load a local URL:

    @
    #include <QApplication>
    #include <QUrl>
    #include <QDesktopServices>
    #include <QMessageBox>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QString qsHelpDoc = QCoreApplication::applicationDirPath() + "/HTML/index.html";
    QUrl qurl = QUrl( QUrl::fromLocalFile&#40; qsHelpDoc&#41;);
    qurl.setQuery( "second_topic.htm");
    
    QMessageBox::information( NULL, "URL to Open:", qurl.toString());
    
    bool bIsValid = qurl.isValid();
    QMessageBox::information( NULL, "",
     bIsValid? "URL is Valid" : "URL is not valid");
    
    QDesktopServices::openUrl( QUrl( qurl));
    

    }
    @

    The URL being loaded is a help file with several help topics, and I'm trying to open a specific topic to do context-sensitive help.

    The full URL as constructed by the code is:

    file:///c:/test/HTML/index.html?second_topic.htm

    And I can type this URL into the address bar in Firefox and go to the correct help topic, so the URL looks good. However, QDesktopServices::openUrl() appears to strip out the query string and only passes this to the browser:

    file:///c:/test/HTML/index.html

    The end result is that the incorrect help topic is displayed. This same result occurs in Windows Qt 5.1.1 and OS X Qt 5.2.1.

    Anybody see what I'm doing wrong?

    Thanks,
    Kevin

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Welcome to forum. This seems to be perfect query. I tried on 520 and it works the way you specified. Can you check with some other url or just open index.html first ? Does this work ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NetZwerg
        wrote on last edited by
        #3

        Why are you prepending your qurl variable of type QUrl() with a QUrl constructor in call to openUrl()? Probably won't solve the problem, but its still not required.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MauriceCat
          wrote on last edited by
          #4

          Deehandra,

          Thanks for the suggestions.

          I first tried opening:

          file:///c:/test/HTML/index.html

          followed by the full URL of:

          file:///c:/test/HTML/index.html?second_topic.htm.

          But, the query string still gets dropped from the full URL.

          What's interesting is that if I open this remote URL:

          @
          QDesktopServices::openUrl( QUrl( "https://www.google.com/?gws_rd=ssl#q=Qt"));
          @

          the query string goes through to the browser and Google does a search on "Qt".

          Now, if I save the Google home page to the local HTML file C:\test\Google.htm and then try to open the following URL with openURL():

          file:///C:/test/Google.htm?gws_rd=ssl#q

          then the browser does not get the query string and only sees:

          file:///C:/test/Google.htm

          So, it looks like query strings go through to the browser for remote URLs, but not for local file URLs.

          NetZwerg,

          Good point. I removed the QUrl() prepend and changed:

          QUrl qurl = QUrl( QUrl::fromLocalFile( qsHelpDoc));

          to this simpler version:

          QUrl qurl = QUrl::fromLocalFile( qsHelpDoc);

          But, as you suspected, this did not make a difference.

          Thanks for your time, guys.

          Kevin

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved