简体   繁体   中英

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.

我不知道问题是什么,但通常最好不要在代码文件中包含任何非ASCII字符,而是完全用英语编写代码并使用Qt的国际化概念(tr,QTranslator,语言学家)来翻译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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM