4

I´m using a QTextBrowser to display an external html document (and its image resources) which is placed in the same directory as the application. Everything works fine exept that images are not displayed properly. Instead of the actual picture there is a "missing image" icon.

Using Ubuntu 12.04 I didn´t have this problem but in Windows 7 it does not work as expected (which I described before).

I tried different image formats and Qt versions, without success.

If I type in the absolute file path of the image it is displayed fine. But that´s not what I´d like to do as I can´t share my application then.

This is the part which 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 anybody has an idea why it doesn´t display the image?

Thanks in advance,

Peter

Peter
  • 41
  • 3

1 Answers1

-2

I would say that the image path is simply incorrect because its currently relative but you're having to address the HTML file as absolute.

To test, try using an absolute URL on your image src to see if it works. You could try using one from the internet then try one on your local file system.

If they both work with absolute URLs, then you'll just need to look into getting the correct file path into your HTML document.

I hope this helps you to debug the problem. Sorry I don't have a precise answer, I'm also new to QT.

Pakage
  • 684
  • 7
  • 12