gpt4 book ai didi

c++ - 嵌入式系统中不显示汉字(yocto,Qt 5.5.1)——为什么 Qt 不使用系统字体?

转载 作者:行者123 更新时间:2023-11-30 04:50:11 25 4
gpt4 key购买 nike

虽然以下代码适用于桌面 Linux 和 Windows,但中文字符在嵌入式 Linux(yocto jethrow、Qt 5.5.1、X11 上的 Qt)上显示为空白。似乎 Qt 使用自己的字体而不是该系统上的系统字体。注意:“Hello World”后面应该有中文的“你好”。

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-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脚本,我还得设置字体。但是,如果我使用网络引擎浏览器小部件,它可以显示中文字符。

命令“fc-list”(liberation、wqy-microhei)和qt函数“Qt.fontFamilies()”(bitstream、luxi、dejavu、curier、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。为了使用 X11vnc,它被切换到 X11。

关于c++ - 嵌入式系统中不显示汉字(yocto,Qt 5.5.1)——为什么 Qt 不使用系统字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55093818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com