Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How do setSource() and setSearchPaths() in QTextBrowser work together?

    General and Desktop
    3
    5
    255
    Loading More Posts
    • 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.
    • R
      Robert Hairgrove last edited by

      One function takes a QUrl object as parameter, the other a QStringList. The documentation says this about the QTextBrowser::source property:
      "When setting this property QTextBrowser tries to find a document with the specified name in the paths of the searchPaths property and directory of the current source, unless the value is an absolute file path. It also checks for optional anchors and scrolls the document accordingly."

      I have some HTML files embedded in the Qt resource file. I have defined virtual folders "/help" and "help/images". So when I load the HTML file and write:

      ui->browser->setSource(QUrl("qrc:/help/index.html"));
      

      it works. However, if I set searchPaths to "qrc:/help" and "qrc:/help/images", then write:

      ui->browser->setSource(QUrl("index.html"));
      

      it cannot find the file. I haven't tried any images yet, because I do not know how I am supposed to do this. There will eventually be more paths depending on languages.

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Robert Hairgrove last edited by

        @robert-hairgrove I guess setSearchPaths() only works for file system, not resources.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • R
          Robert Hairgrove last edited by

          In the meantime, I tried loading a page with one image. As long as I include the subdirectory in the image src tag, it is found, even without setting searchPaths at all. The image and the HTML page are actually in the same physical qrc folder (as required by Qt, at least -- actually I am putting symlinks to the real files there so that I have a little more organization in my work). So it appears that the virtual folders defined in the resources are found OK.

          Then the question remains: What can searchPaths do for me? Does someone have an example?

          1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            searchPaths() is using QFileInfo(foo).isReadable() - I would check what this gives for you to see if maybe QFileInfo can't handle qrc urls.

            See https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qtextbrowser.cpp.html#_ZNK19QTextBrowserPrivate8findFileERK4QUrl

            Qt has to stay free or it will die.

            R 1 Reply Last reply Reply Quote 1
            • R
              Robert Hairgrove @Christian Ehrlicher last edited by

              @christian-ehrlicher Thanks for this useful link. Perhaps I should use the ":/" scheme when setting searchPaths? The findFile() function transforms "qrc:/" into ":/" before doing the actual search. I will try this.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post