Results 1 to 2 of 2

Thread: QWebView and QByteArray: encoding error

  1. #1
    Join Date
    Apr 2011
    Location
    Bayreuth, Bayern
    Posts
    24
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default QWebView and QByteArray: encoding error

    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!

  2. #2
    Join Date
    Apr 2011
    Location
    Bayreuth, Bayern
    Posts
    24
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWebView and QByteArray: encoding error

    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!

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 09:51
  2. Encoding/Decoding and SQL
    By alexandernst in forum Qt Programming
    Replies: 0
    Last Post: 1st February 2011, 11:16
  3. QTextCodec bad encoding?
    By ComaWhite in forum Newbie
    Replies: 0
    Last Post: 18th September 2009, 06:15
  4. Replies: 9
    Last Post: 25th July 2009, 13:27
  5. Encoding a QString to No.?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 30th August 2007, 19:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.