QDesktopServices::openUrl() not working correctly



  • Consider the following code:

    void UI_myapp::helpbuttonpressed()
    {
    #ifdef Q_OS_LINUX
      QDesktopServices::openUrl(QUrl("file:///usr/share/doc/myapp/manual.html#name_of_anchor"));
    #endif
    
    #ifdef Q_OS_WIN32
      char p_path[MAX_PATH_LENGTH];
    
      strcpy(p_path, "file:///");
      strcat(p_path, mainwindow->specialFolder(CSIDL_PROGRAM_FILES).toLocal8Bit().data());
      strcat(p_path, "\\myapp\\manual.html#name_of_anchor");
      QDesktopServices::openUrl(QUrl(p_path));
    #endif
    }
    

    On Linux it works as expected, it opens the html file with the default browser and jumps
    to the specified anchor.

    On windows however, it opens the html file but it ignores the specified anchor.

    Qt version is 4.8.7.

    Is this normal behaviour, a bug or is there something wrong with my code?


  • Moderators

    @Trino
    are you using the same browser on both platforms during testing?

    I wasn't aware that the stuff the anchor feature would work at all.
    On windows you can test this, by creating a custom shortcut/link (e.g. on the desktop) with the url and check if it behaves the same.
    If so there is nothing you can do. If it works also there then maybe Qt's internal implementation drops the anchor somewhere.



  • Can you see the anchor in the location bar of your browser? If so the URL is completely passed to the browser and it sounds like a bug in your used browser... If the anchor it's not in the location bar it was dropped anywhere (by Qt? by the platform? ....) and the browser can't jump to the anchor.


  • Moderators

    Not an answer to your question: why do you use \ in strcat(p_path, "\myapp\manual.html#name_of_anchor");? You can use /
    Another thing: why do you use strcpy/strcat? Why not use QString which is more high level? In the end you're using C++ not C :-)



  • @raven-worx
    Yes, I use the latest version of Firefox on both platforms.
    When I copy the link into "run" (by pressing windows-key + r), the result is the same.
    Looks like a windows issue.



  • @micland
    No, the anchor isn't visible in the location bar of the browser.



  • @jsulm
    Because I prefer plain C over C++ :-)
    I only use C++ when I can't avoid it e.g. when dealing with Qt.


  • Moderators

    @Trino said:

    Looks like a windows issue.

    yes, maybe.
    Possibly Windows already cleans the url up before making the actual call.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.