PDA

View Full Version : QWebView and QByteArray: encoding error



missoni
16th May 2011, 00:03
Hello!
I have been sitting on the same problem for over three days now and I cannot figure out what is wrong with my code.

Im my program, I use a QWebView window to represent HTML content. This HTML content is generated on-the-fly, based on user settings. I use QXmlStreamWriter to generate HTML file. QXmlStream needs a QIODevice, so I create a QByteArray, write HTML code into it and in the end I create a QString out of the QByteArray. When I print this code in the QWebView, it does not display special symbols (like German Umlauts or Russian letters) correctly. However, if I save the generated code to an HTML file, Firefox opens displays these characters correctly.

The generated HTML contains <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> tag.

I have already tried setting a codec for strings, and converting string to different formats and playing around the QByteArray itself. I use Qt 4.7.3. for Windows Desktop with MinGW 4.4.

I guess, I am missing an important point in the encoding story, and I would be grateful for any help! The problem is really annoying and it is preventing me from completing my idea! Thank you!

missoni
16th May 2011, 22:41
Okay, I solved my issue.

In the documentaion it says that QString::QString(QByteArray&) converts a byte array to a strong using QString::fromAscii() function. I replaced this part with QString::fromUtf8(myByteArray), and it worked!