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 fails to open on Windows Platform.
Forum Updated to NodeBB v4.3 + New Features

QDesktopServices::openUrl fails to open on Windows Platform.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.7k 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.
  • D Offline
    D Offline
    DalePennington
    wrote on last edited by
    #1

    Folks,

    We have a function to build a file path to a local HTML file and invoke QDesktopServices::openUrl to open it. It works fine on the RHEL 8 platform, but fails on the Windows 10 platform (build in a MinGW64 environment). This is using Qt 5.15.

    My understanding from the documentation that the only way to fail is to not launch the browser, but how can we determine why it fails beyond the simple Yes/No failure message we get from the Boolean.

    Thanks,
    Dale Pennington

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Based on the Qt 5.15.2 backend code, you should have a warning printed on the command line in case of problems.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DalePennington
        wrote on last edited by
        #3

        When we do a run, we get the following error :

        -- Error: ShellExecute 'c:%5CCrossCheck-OSC-mod2%5C%5Cshare%5Cdoc%5Cxpatch-4.17.1%5Carchitecture%5Cmodel_tools%5Ccrosscheck%5CCrossCheckTOC.html' failed (error 2).

        Given that %05C is the backslash character ('') that Windows uses as delimeters, and that a file exists at that path, I am not sure what to look at next.

        1 Reply Last reply
        0
        • D DalePennington

          Folks,

          We have a function to build a file path to a local HTML file and invoke QDesktopServices::openUrl to open it. It works fine on the RHEL 8 platform, but fails on the Windows 10 platform (build in a MinGW64 environment). This is using Qt 5.15.

          My understanding from the documentation that the only way to fail is to not launch the browser, but how can we determine why it fails beyond the simple Yes/No failure message we get from the Boolean.

          Thanks,
          Dale Pennington

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @DalePennington said in QDesktopServices::openUrl fails to open on Windows Platform.:

          We have a function to build a file path to a local HTML file and invoke QDesktopServices::openUrl to open it.

          What is the path you built, as passed to openUrl()?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DalePennington
            wrote on last edited by
            #5

            The code chunk in question is :

              // Replace all forward slashes with QDir::separator (in case we ever go to Windows)
              QString delimitedDocsPath = docsPath.replace("/", QDir::separator());
            
              if (QFile::exists(delimitedDocsPath))
              {
                if (!QDesktopServices::openUrl(QUrl(docsPath)))
                {
                  std::string msg = "Error occured while loading ";
                  msg += docsPath.toStdString();
                  msg += " in default browser.\n";
                  _crossCheckMessageDialogImpl->AppendStatusMessage(msg);
                }
              }
            

            So what we print in the error dialog when we have the problem is :

            Error occured while loading C:\CrossCheck-OSC-2\\share\doc\xpatch-4.17.1\architecture\model_tools\crosscheck\CrossCheckTOC.html in default browser.
            

            So what we print is the path before we replaced the Dir seperator with windows seperator, the modified path passed an exists check before being passed to openUrl and then we got the in code error as noted just above, and the debug error as reported in my previous reply.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              The double backslash looks fishy.

              In any case, you should not need to do that conversion by hand. The only time you would need that is if you have to call an external library with such a path. Otherwise, as long as you use Qt, use forward slashes everywhere. Qt will do the conversion when needed.

              You should also use QUrl::fromLocalFile to build your URL.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply
              3
              • SGaistS SGaist

                The double backslash looks fishy.

                In any case, you should not need to do that conversion by hand. The only time you would need that is if you have to call an external library with such a path. Otherwise, as long as you use Qt, use forward slashes everywhere. Qt will do the conversion when needed.

                You should also use QUrl::fromLocalFile to build your URL.

                D Offline
                D Offline
                DalePennington
                wrote on last edited by
                #7

                @SGaist
                Went with your suggested implementation changes, and it all appears to work now.

                Thanks

                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