PDA

View Full Version : Why the images from the HTML file is not loaded??



rleojoseph
1st March 2011, 07:16
Am trying to insert the HTML file in the TextEdit !! After inserting, only the Texts and Links are being loaded in the TextEdit widget. Why the images are not loaded ???

Lykurg
1st March 2011, 07:24
Maybe the path (href) is not valid. Or try to embed them. See the wiki article I have wrote long time ago: QTextBrowser with images and CSS (It might be not any more state of the art, but should still work.)

rleojoseph
1st March 2011, 08:11
Thanks sir, But am trying to insert a saved html file in the TextEdit !

Lykurg
1st March 2011, 08:19
How are the href defined? You can alter the HTML files and add a "base href" or still load the images to the resource file.

rleojoseph
1st March 2011, 08:28
am using the following code

QFile inputFile(filename);
inputFile.open(QIODevice::ReadOnly);
QTextStream in(&inputFile);
QString line = in.readAll();
//in.setCodec("UTF-8");
inputFile.close();
QTextCursor cursor=textEdit->textCursor();
cursor.insertHtml(line);

Lykurg
1st March 2011, 08:48
...and? It probably would be helpful if you post an example of the actual HTML you are about to insert. :)

rleojoseph
1st March 2011, 08:51
Assume that i have save a webpage from this link http://doc.qt.nokia.com/4.7/classes.html. I have saved this webpage in my system and trying to insert it .

Lykurg
1st March 2011, 09:38
Look, a QTextEdit is not intended to display whole webpages. Use webkit for it. If you still want to use the text edit, you have to embed all images into the resource or adjust the file paths. You then also have to go through the css files! But that is really pain in the a***

Berryblue031
2nd March 2011, 12:29
Lykurg about your wiki article, I use a similar system for displaying images in a QTextBrowser, we have a system where I make a request to the database/server (depending whether we are offline or online) to get the html and then I intercept the QTextBrowser::loadResource calls to load any images/audiofiles from the appropriate datasource, then I call qtextdocument.add resource like in your article.

My question is can i trust the QTextBrowser's resource cache to limit itself to a respectable size or should I worry about unloading the resources manually? ( I don't know much about how it's resource cache works )