View Full Version : QString unicode problem

21st September 2010, 12:53

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?

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

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

21st September 2010, 13: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?

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

21st September 2010, 16: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.

21st September 2010, 16: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.