Unsolved How do setSource() and setSearchPaths() in QTextBrowser work together?
-
One function takes a
QUrl
object as parameter, the other aQStringList
. The documentation says this about theQTextBrowser::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.
-
@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 settingsearchPaths
at all. The image and the HTML page are actually in the same physicalqrc
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? -
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 settingsearchPaths
? ThefindFile()
function transforms"qrc:/"
into":/"
before doing the actual search. I will try this.