PDA

View Full Version : Append content to QWebView



thrall
2nd November 2010, 18:50
Hello,

I search for a way to append content to a QWebView, like the way it is possible with QTextBrowser::append(), in order to show small html fragments that may contain external content like pictures (gif) or youtube video. Is that possible :confused:

Or should I rather try to do this with QTextBrowser. Then I have the vague idea that I have to add some mime-thing for the file formats to support in oder to load them from external. But I do not have any clue how to achieve that. :(

Regards

tbscope
2nd November 2010, 19:02
http://doc.qt.nokia.com/4.7/qwebview.html#setHtml
http://doc.qt.nokia.com/4.7/qwebview.html#setPage

thrall
2nd November 2010, 20:03
http://doc.qt.nokia.com/4.7/qwebview.html#setHtml
http://doc.qt.nokia.com/4.7/qwebview.html#setPage

I knew setHtml(). With this function I can set the content, but not append() to existing content :(

MTK358
4th November 2010, 01:15
You can't append to an HTML file because it must end with the </html> tag.

Maybe if you have the current HTML stored somewhere you can remove the </html> tag, append HTML code, and then append "</html>"?

thrall
4th November 2010, 18:19
You can't append to an HTML file because it must end with the </html> tag.

Maybe if you have the current HTML stored somewhere you can remove the </html> tag, append HTML code, and then append "</html>"?

I hoped QWebView would provide something like that.

Now I have decided to write my own class, derived from QWebView, storing the content in local QString member variable and setting the content after change in QWebView. The should be very easy ;-)

However, I would like to make shure that the resulting document is a vaild html format. Can someone suggest an small and lightwight (free) html checker, available as library or source?

rsilva
18th April 2011, 05:08
You can do it using the easy way:
webView->page()->mainFrame()->evaluateJavaScript("document.body.innerHTML += [your code]");

Using scripts you can dynamically "talk" with the HTML DOM.

in the [your code] i'm using a "window.bridge.code" with addToJavaScriptWindowObject.

But you can simples put your text there, or use "document.body.innerHTML += '" + code + "';";

^^

didac.perez
19th August 2013, 17:32
http://doc.qt.nokia.com/4.7/qwebview.html#setHtml
http://doc.qt.nokia.com/4.7/qwebview.html#setPage

He's asking for append, not for set