Results 1 to 3 of 3

Thread: Qt Text Encoding and the British pound sign

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt Text Encoding and the British pound sign

    The pound symbol is Unicode code point U+00A3, 163 in decimal. Using QString(163) causes an implicit conversion to a Unicode QChar using the short/int constructor so that the compiler can use it in the QString constructor.

    The two characters the OP saw are the result of treating the two bytes that U+00A3 occupies in UTF8 (\xC2 \xA3) as two separate characters in ISO8859-1 (Latin1) or a similar 8-bit encoding. Assuming the original poster was using an editor saving in UTF8 encoding this would have worked:
    Qt Code:
    1. qDebug() << QString::fromUtf8("text £%1 text").arg(1000); // literally typing the pound symbol into the string
    2. // output is
    3. "text £1000 text"
    To copy to clipboard, switch view to plain text mode 
    and been easier to understand than QString(163).

    156 is the position of the £ symbol in "Code Page 437" used by IBM in the original PC to extend the 7-bit ASCII code. AFAICT Qt has no way to convert from this encoding.
    Last edited by ChrisW67; 4th October 2012 at 04:30.

Similar Threads

  1. QSqlQuery text encoding change MySQL4 -> MySQL5
    By theophilus in forum Qt Programming
    Replies: 1
    Last Post: 15th January 2010, 13:29
  2. Character encoding in text edit and llne edit
    By greenvirag in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 08:45
  3. Euro sign
    By dragon in forum Qt Programming
    Replies: 3
    Last Post: 8th September 2008, 19:58
  4. Problems with text encoding
    By LMZ in forum Qt Programming
    Replies: 4
    Last Post: 3rd July 2007, 12:49

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
  •  
Qt is a trademark of The Qt Company.