View Full Version : Unicode strings int Qt 4.2.1

6th August 2007, 13:38
Hi everyone!

I'm editing source code with Eclipse with UTF-8 character set to all files in project. But when I try to wrote Cyrillic characters directly in source code, in execution I got to unpleasant symbols, not what I wrote.

Where I'm was wrong?

6th August 2007, 13:48
Use QTextCodec::setCodecForCStrings to set a codec before using any QStrings.
This can be done in main.cpp, right after instantiating the QApplication object.

QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("ISO-8859-5"));

This is just an example to show you how it's done. I am not sure if that is the standard Cyrillic encoding name.


6th August 2007, 14:11
Yes, it's worked. I use "UTF-8" as param. Thank's!!! : )))

6th August 2007, 14:38
still not working for me....I'm trying to add unicode chars and this is the error I get in visual c++

warning C4566: character represented by universal-character-name '\u03C3' cannot be represented in the current code page (1252)

I'm trying to add the chars sigma and mu to the status bar.

any help would be appreciated :)



6th August 2007, 14:49
Use and UTF-8 codec for C strings, as shown above.
Do not give the unicode codes for the two chars.
Instead write the char directly in code:

QString sigma = "σ";
Next, if you set the codec correctly, you can set this string to the status bar.

If you really want to use Unicode codes, than you can try QString::fromUtf16( or one of the other conversion functions )


6th August 2007, 14:59
still getting same here when I'm compiling.....do I need to change the format the document is saved as?

right now it is set to: unicode - codepage 1200

I've also tried unicode (UTF-8 with signature) code page 65001

thanks for your help!

6th August 2007, 15:02
Yes, change the encoding to UTF-8
Are you using Eclipse also?

6th August 2007, 15:03
yeah, changed the encoding to utf-8 and using visual c++ 2005 express edition

6th August 2007, 15:10
Well, is it working?

6th August 2007, 15:13
no dice so far, and I've tried a bunch of different file formats.....is this a compiler thing maybe?

6th August 2007, 15:34
QChar chr[] = {0X03c3};
QString xxx = QString::fromRawData(chr, 1);

EDIT: don't forget to set the unicode codec in main.cpp.


6th August 2007, 15:43
working like a charm, many thanks!

29th December 2011, 09:02
I use Eclipse IDE for C/C++ & QT integration plug-in , but I'm not write Unicode ?
How to resolve ? Thank every body.
Example: I write : "Chà o tất cả các bạn!" but It show in program: "Chà o t?t c? các b?n"