PDA

View Full Version : QString unicode problem



kemp
21st September 2010, 11:53
Hi,

I cannot get the right text into the QString.



QByteArray ba = "abcčćžšđ ABCČĆŽŠĐ."; //OK
char* cTmp = ba.data(); //OK
QString sTmp1 = "abcčćžšđ ABCČĆŽŠĐ."; //NOT OK - data = "abc�枚� ABC�Ǝ��."
QString sTmp2 = QObject::trUtf8("abcčćžšđ ABCČĆŽŠĐ."); //NOT OK - data = "abc�枚� ABC�Ǝ��."


I have also set:



QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("UTF-8"));


What am I doing wrong?

nish
21st September 2010, 12:04
try to do QString sTmp1 = ba;

kemp
21st September 2010, 12:10
I have already tried this and I get also wrong characters.

kemp
21st September 2010, 12:30
I made a blank project with just



QString sTmp1 = "abcčćžšđ ABCČĆŽŠĐ."; //OK


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

wysota
21st September 2010, 13:34
I would say your file is not utf-8 encoded.

kemp
21st September 2010, 15:05
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.

wysota
21st September 2010, 15:11
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.