PDA

View Full Version : Cannot get QT Gui Application to display chinese



Weichen
18th September 2010, 17:30
Hello, I am new to the QT SDK 4.6.1 and currently learning qt through C++-GUI-Programming-with-Qt-4-1st-ed

I am trying to display some chinese words in a simple qt windows and it shows up all rubbish.

here is the code



#include <QApplication>
#include <QLabel>

int main( int argc, char* argv[])
{
QApplication App(argc,argv);
QLabel *label = new QLabel("XXXX"); //where XXXX is chinese character
label -> show();
return app.exec()
}

The code ran well and showed a little windows, the only problem is that the chinese character are messed up.

It would be nice if someone can show me how to solve these problems or I might as well just go back to MFC.

ps.
I've been search through internet for solutions; however, nothing mentionable has been found. I've read the internationlization with QT and tried


QString text = "XXXX";
QLabel *label = new QLabel(text);


and it did not work. I donno the tr() function as there is no real example that solved the multi-langue display problem

tbscope
18th September 2010, 17:41
http://doc.qt.nokia.com/4.7-snapshot/internationalization.html

wysota
18th September 2010, 22:47
In what encoding is the chinese character you are trying to put into this QString?

Weichen
18th September 2010, 22:52
In what encoding is the chinese character you are trying to put into this QString?

I want to encode traditional chinese. It would be nice if I am able to encode simpliied chinese too

wysota
18th September 2010, 22:57
No, you didn't understand me. I'm asking what is the text encoding of the characters you input in the file. I'm not asking whether it is simplified or traditional, I'm asking about the glyph encoding. If you don't know what that is, please ask your favourite web search engine. I can give you a hint, it could be BIG-5, but it could also be UTF-8 or something else.

You can start reading here: http://en.wikipedia.org/wiki/Chinese_character_encoding

jezz
19th September 2010, 00:51
wysota was correct.
For specific details on Qt and Chinese characters, refer http://hi.baidu.com/cyclone/blog/item/9d7293130e5a498d6538dbf1.html

Weichen
19th September 2010, 05:42
wysota was correct.
For specific details on Qt and Chinese characters, refer http://hi.baidu.com/cyclone/blog/item/9d7293130e5a498d6538dbf1.html

Thank you. that blog was a great help