嵌入式系统中未显示的中文字符(yocto,Qt 5.5.1) - 为什么Qt不使用系统字体?

Chinese characters not shown in embedded system (yocto, Qt 5.5.1) - why Qt doesn't use system fonts?

本文关键字:Qt 系统 为什么 字体 显示 中文 yocto 字符 嵌入式      更新时间:2023-10-16

虽然以下代码在桌面linux和Windows上都可以使用,但汉字在嵌入式Linux上显示出汉字(Yocto jethrow,qt 5.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();

在另一个使用QT 4的嵌入式系统上,仅安装合适的字体就足够了。该字体也可以在此处正确安装,并由FC列表识别。

如果我修改上面的代码并直接设置字体,则可以按预期工作:

// 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()"(bitstream,luxi,dejavu,dejavu,curier,Cursor,Cursor,Cursor,utopia)是不同的。

是否可以在不重新编译QT或应用程序的情况下更改QT配置,以使WQY-Microhei用于汉字?

尽管此嵌入式系统在x11上使用QT,但该解决方案是将字体复制到/usr/lib/fonts中,如下所述:

https://doc.qt.io/qt-5/qt-embedded-fonts.html

似乎在此系统上QT/X11集成尚未完成。用作基础的Yocto Meta-QT5层默认情况下未使用X11。它被切换到X11,以便使用X11VNC。