我曾经问过Qt类似的问题,Qt官方的回答如下
Furthermore the wrong textrendering is not related to Windows CE at all. You
can recognize the same on an English Windows XP installation. As
fromLocal8Bit uses the local encoding, it will use the english one on an
english system. Thus, usage of Qt's internationalization is suggested. I
recommend to use English strings inside your source code and translate them
using the QObject::tr()/QObject::trUtf8(). For more information about our
internationalization system, continue reading at:
http://doc.trolltech.com/4.3/i18n.htmlhttp://doc.trolltech.com/4.3/linguist-manual.htmlIn case you are sure you want to use Asian letters inside the source code
regardless the system to be run on, you can take a look at the source code
attached to this email. There it passes the character as raw data to a
QByteArray and encodes it manually by setting the codec for a QTextStream..
However, this is a very unconvenient solution and above described way is
much more recommended.
Best Regards,
Maurice Kalinowski
#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QTextCodec>
#include <QTextStream>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setFont(QFont("SimSun", 18, QFont::Bold));
QByteArray ba("いゅ");
QTextStream s(&ba);
s.setCodec("Big5");
QString str;
s >> str;
QPushButton quit(str);
quit.resize(75, 30);
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
不推荐直接在程序源代码中使用中文字符,推荐使用QT的国际化功能。直接使用中文可能会在不同的平台上产生不同的效果,这与程序使用的默认本地解码器有关。
而且tr本来就是支持国际化的工具,直接用国际化更能会非常完美的解决这些问题。