开发者

Can't show chinese character in Qt-Embedded 4.7.3

I开发者_开发技巧'm using Qt-Embedded 4.7.3 and trying to show Chinese characters in the widgets. I've built a x86 version of Qt-embedded so that I can test my application using qvfb. But I can not show chinese due to some unknown reason. Here is a test program I use:

#include <QApplication>
#include <QLabel>
#include <QTextCodec>

int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));

  QLabel* label = new QLabel("Chinese中文");
  label->show();

  return app.exec();
}

I have 'WenQuanYiMicroHeiLight.ttf' chinese font installed under lib/fonts. The Chinese characters are encoded in UTF-8, so according to the Qt Documment, this should allow me to display chinese in the widget. But when I run the application in QVFB, it's didn't show chinese.

Any ideas?

EDIT: Later I found out it's actually caused by the system(not really sure though). I switched to Debian and the Chinese are showing again. It might be related to package dependency problems on my old system (ArchLinux but holding gnome2 packages...)

Thanks for the answers.


I don't know what the problem is, but it's usually better to not include any non-ASCII characters in the code files, but write the code entirely in English and use Qt's internationalization concept (tr, QTranslator, linguist) to translate the Gui.


Don't you have to translate strings? Here's another good article.

Try QLabel* label = new QLabel(tr("Chinese中文")); maybe. It's a start at least.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜