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. Can't open an HTML on a specific fragment in QT using hash

Can't open an HTML on a specific fragment in QT using hash

Scheduled Pinned Locked Moved Solved General and Desktop
htmlqurlqdesktopservice
3 Posts 2 Posters 745 Views
  • 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.
  • A Offline
    A Offline
    a1rltt
    wrote on 20 Jul 2020, 04:35 last edited by a1rltt
    #1

    I tried this:

    QDesktopServices::openUrl(QUrl("file:///" + QCoreApplication::applicationDirPath() + "/HELP.html#pers"));
    

    this:

    QUrl url = QCoreApplication::applicationDirPath() + "/HELP.html";
    url = QUrl::fromLocalFile(url.toString());
    url.setFragment("pers");
    QDesktopServices::openUrl(url);
    

    and with just full path, like in browser's search bar:

    QDesktopServices::openUrl(QUrl("file:///D:/ucheba/GPO/build-ReeGO-Desktop_Qt_5_13_2_MinGW_32_bit-Release/release/HELP.html#pers"));
    

    in these cases HTML opens, but just in the beginning of the document, ignoring hash (#).

    Id is correct - when i use it for linking in browser, #pers appears in a browser's search bar and HTML opens in correct place.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on 20 Jul 2020, 06:38 last edited by Bonnie
      #2

      Hello, are you running in Windows?
      If yes, that's not Qt's fault to blame. Qt pass the whole url to ShellExecute Api.
      But as discussed in this stackoverflow post:

      when processing File:/// based URLs in ShellExecute(), the ShellExecute() call will strip off the # and any data it finds after the # before launching the default browser and sending in the HTML page to open. MS's stance is that they do this deliberately to prevent injections into the function.

      A 1 Reply Last reply 20 Jul 2020, 10:30
      6
      • B Bonnie
        20 Jul 2020, 06:38

        Hello, are you running in Windows?
        If yes, that's not Qt's fault to blame. Qt pass the whole url to ShellExecute Api.
        But as discussed in this stackoverflow post:

        when processing File:/// based URLs in ShellExecute(), the ShellExecute() call will strip off the # and any data it finds after the # before launching the default browser and sending in the HTML page to open. MS's stance is that they do this deliberately to prevent injections into the function.

        A Offline
        A Offline
        a1rltt
        wrote on 20 Jul 2020, 10:30 last edited by
        #3

        @Bonnie yes, i'm on Windows, thanks for the explaining!

        1 Reply Last reply
        0

        3/3

        20 Jul 2020, 10:30

        • Login

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