虽然下面的代码可以在桌面Linux和Windows上运行,但中文字符在嵌入式linux上显示为空白(yocto jethrow,Qt 5.5.1,X11上的Qt )。Qt似乎使用它自己的字体,而不是这个系统上的系统字体。注:在"Hello World“之后应该有中文的"nihao”。
main()的C++内容:
QApplication a( argc, argv );
QString s = QString::fromUtf8("Hello world \u611b!");
QPushButton hello;
// eventually set font here, see below
hello.setText(s);
hello.resize( 200, 30 );
hello.show();
return a.exec();在另一个使用Qt4的嵌入式系统上,只需安装适当的字体即可。字体也被正确地安装在这里,并被fc-list识别。
如果我修改上面的代码并直接设置字体,它会按预期工作:
// insert font here:
int id = QFontDatabase::addApplicationFont("/usr/share/fonts/wqy/wqy-microhei.ttc");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont font(family);
hello.setFont(font);
// end modification
hello.setText(s);如果我创建一个简单的qml脚本,我还必须设置字体。但是,如果我使用web引擎浏览器小部件,它可以显示中文字符。
命令"fc-list“(释放,wqy-microhei)和qt函数”Qt.fontFamilies()“(位流,luxi,dejavu,curier,cursor,utopia)显示的字体是不同的。
是否可以在不重新编译qt或应用程序的情况下更改qt配置,以便将wqy-microhei用于中文字符?
发布于 2019-03-11 09:40:54
尽管此嵌入式系统在X11上使用Qt,但解决方案是将字体复制到/usr/lib/fonts中,如下所述:
https://doc.qt.io/qt-5/qt-embedded-fonts.html
似乎Qt/X11集成在此系统上并不完整。被用作基础的yocto meta-qt5层在默认情况下没有对该主板使用X11。为了使用X11vnc,它被切换到X11。
https://stackoverflow.com/questions/55093818
复制相似问题