PDA

View Full Version : Unicode strings int Qt 4.2.1



mkrentovskiy
6th August 2007, 14: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?

marcel
6th August 2007, 14: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.
Example:


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.

Regards

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

JonathanForQT4
6th August 2007, 15: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 :)

thanks,

Jonathan

marcel
6th August 2007, 15: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 )

Regards

JonathanForQT4
6th August 2007, 15: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!

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

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

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

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

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


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

regards

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

thaihoangluu
29th December 2011, 10: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"