Results 1 to 7 of 7

Thread: QString unicode problem

  1. #1
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QString unicode problem

    Hi,

    I cannot get the right text into the QString.

    Qt Code:
    1. QByteArray ba = "abcčćžšđ ABCČĆŽŠĐ."; //OK
    2. char* cTmp = ba.data(); //OK
    3. QString sTmp1 = "abcčćžšđ ABCČĆŽŠĐ."; //NOT OK - data = "abc�枚� ABC�Ǝ��."
    4. QString sTmp2 = QObject::trUtf8("abcčćžšđ ABCČĆŽŠĐ."); //NOT OK - data = "abc�枚� ABC�Ǝ��."
    To copy to clipboard, switch view to plain text mode 

    I have also set:

    Qt Code:
    1. QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QString unicode problem

    try to do QString sTmp1 = ba;

  3. #3
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QString unicode problem

    I have already tried this and I get also wrong characters.
    Last edited by kemp; 21st September 2010 at 12:24.

  4. #4
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QString unicode problem

    I made a blank project with just

    Qt Code:
    1. QString sTmp1 = "abcčćžšđ ABCČĆŽŠĐ."; //OK
    To copy to clipboard, switch view to plain text mode 

    and it works, so there is something wrong with my project.
    Has anyone encountered a similar problem?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString unicode problem

    I would say your file is not utf-8 encoded.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QString unicode problem

    Quote Originally Posted by wysota View Post
    I would say your file is not utf-8 encoded.
    You were right it was not utf-8 encoded, but the problem still exists. I found out that the problem is only on windows, Linux and Mac are working ok. But I am happy with that, because I need the binary only for Linux and Mac. I am just wondering why this is happening on windows.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString unicode problem

    Quote Originally Posted by kemp View Post
    Linux and Mac are working ok.
    Those systems have a different default codepage than Windows. That's one of the reasons why you should always use UTF-8, regardless of the platform.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Putting unicode in QString literals
    By reddish in forum Qt Programming
    Replies: 3
    Last Post: 30th October 2012, 01:25
  2. QSettings unicode problem
    By mgiza in forum Qt Programming
    Replies: 2
    Last Post: 2nd September 2011, 23:01
  3. QString Unicode conversion
    By user_mail07 in forum Qt Programming
    Replies: 5
    Last Post: 15th April 2010, 22:16
  4. i have a problem with Qt unicode
    By coder1985 in forum Qt Programming
    Replies: 5
    Last Post: 20th November 2007, 20:08
  5. Unicode Character Problem
    By prakash in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2006, 07:25

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.