QTextBrowser does not display image from html file (Windows 7)

I am using QTextBrowser to display an external html document (and its image resources), which is placed in the same directory as the application. Everything works fine, except the images are not displayed correctly. A "no picture" icon appears instead of the actual image.

Using Ubuntu 12.04 I didn't have this problem, but it doesn't work as expected on Windows 7 (which I described earlier).

I have tried different image formats and Qt versions with no success.

If I type in the absolute path of the image file, it appears ok. But this is not what I would like to do as I cannot share my application.

This is the part that loads the html file into the textbrowser:

QFile file(QApplication::applicationDirPath().append("/test.html"));
if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
    return;

QTextStream in(&file);
ui->textBrowser->setHtml(in.readAll());
file.close();

      

And this is my html document:

<!doctype html>
<html>
    <img src="test.png">
    <p>paragraph which contains some text</p>
</html>

      

Does anyone have an idea why it is not displaying the image?

Thanks in advance,

Peter

+3


source to share


1 answer


I would argue that the image path is just incorrect because it is currently relative, but you have to refer to the HTML file as absolute.

To test, try using the absolute url of your src image to see if it works. You can try using one from the internet and then try it on your local filesystem.



If both of them work with absolute urls, then you just need to examine the correct path to the HTML document file.

Hope this helps you debug the problem. Sorry I have no exact answer, I am also new to QT.

0


source







All Articles