Results 1 to 3 of 3

Thread: Any way to put Unicode character in QString without using QString("%1").arg(QChar)?

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: Any way to put Unicode character in QString without using QString("%1").arg(QChar

    Your C++ compiler will convert the character literal '\u00c7' to the two UTF8 bytes 0xC3 0x87. That is what will be in the C-string that you construct the QString from.

    The Qt4 QString(const char *) constructor will use fromAscii()/fromLatin1() and misinterpret those bytes resulting in two characters in the QString where there should only be one. What you want is this:
    Qt Code:
    1. QString s(QString::fromUtf8("Texte en fran\u00e7ais"));
    2. // or
    3. QString s = QString::fromUtf8("Texte en fran\u00e7ais");
    To copy to clipboard, switch view to plain text mode 

    The Qt5 QString(const char *) constructor will use fromUtf8() so this should be fine:
    Qt Code:
    1. QString s("Texte en fran\u00e7ais");
    To copy to clipboard, switch view to plain text mode 

    On Linux qDebug() will generally do the right thing with strings constructed this way.

  2. The following user says thank you to ChrisW67 for this useful post:

    oddity (13th November 2013)

Similar Threads

  1. Replies: 10
    Last Post: 17th July 2014, 10:52
  2. Replies: 1
    Last Post: 14th May 2011, 08:02
  3. Replies: 28
    Last Post: 22nd February 2010, 10:27
  4. Need definedInHeader("QString") == "q<somewhere>.h"
    By muenalan in forum Qt Programming
    Replies: 6
    Last Post: 29th September 2009, 11:04
  5. Error "QString::arg: Argument missing"
    By Lawand in forum Qt Programming
    Replies: 3
    Last Post: 18th February 2009, 20:26

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.