Display webpage using the source code from a QByteArray
-
wrote on 2 May 2011, 18:44 last edited by
I have a QByteArray which contains the source code of a website.
I want to display, in my application, the website ( like emulating a browser ), but i want to use the source code from my QByteArray.
-
wrote on 2 May 2011, 18:59 last edited by
So? Decode the bytes into a string and use QWebView::setHtml.
-
wrote on 2 May 2011, 19:11 last edited by
@
myWebView->setHtml( QString::fromLatin1( byteArray ) );
@assuming that your QByteArray contains latin1 encoded data.
-
wrote on 2 May 2011, 20:02 last edited by
Normally, the encoding would be somewhere in the first part of the HTML header. You might need to search for that header, and re-parse the document based on what you find. You can not just assume that it is one encoding or the other. Normally, you'd find the encoding information (also) in the HTTP headers, but I gather that you don't have those?
-
wrote on 2 May 2011, 22:20 last edited by
You should try "QWebView::setContent() ":http://doc.qt.nokia.com/4.7/qwebview.html#setContent, it takes a QByteArray as argument.
-
wrote on 3 May 2011, 05:19 last edited by
[quote author="Volker" date="1304374840"]You should try "QWebView::setContent() ":http://doc.qt.nokia.com/4.7/qwebview.html#setContent, it taks a QByteArray as argument.[/quote]
Even better, of course :-)
6/6