Important: Please read the Qt Code of Conduct -

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

  • 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:


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


    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.

  • Lifetime Qt Champion

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

  • 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?

  • Lifetime Qt Champion

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


  • @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.

Log in to reply