PDA

View Full Version : Loading images in html in a QTextBrowser



BasicPoke
1st June 2007, 16:02
Hello all. I am trying to load some simple html into a QTextBrowser and display images, but the images do not load unless I specify the full path to them. I am loading the html with the following:

QTextBrowser *textEdit;
...
QFile file(fileName);
textEdit->setHtml( file.readAll() );

This came from QT's QTextEdit example but I changed it to use QTextBrowser instead of QTextEdit because I want links in the html.

The following html correctly displays the image:
<html>
<img src="d:\1.JPG" />
</html>

The following html shows an image icon instead of the correct image:
<html>
<img src="1.JPG" />
</html>

The image file is in the same folder as the html file. Any ideas how to make this work without providing the full path to the image files?

Thanks
BasicPoke

guilugi
6th June 2007, 21:51
Hello,

You can use textEdit->setSearchPaths( QStringList() << "D:\"), it specifies one or several
directories to search content for :)