【问题标题】:Chinese characters not shown in embedded system (yocto, Qt 5.5.1) - why Qt doesn't use system fonts?嵌入式系统中未显示汉字(yocto,Qt 5.5.1) - 为什么Qt不使用系统字体?
【发布时间】:2019-03-11 00:32:09
【问题描述】:

虽然以下代码适用于桌面 Linux 和 Windows,但在嵌入式 linux(yocto jethrow、Qt 5.5.1、Qt on X11)上,中文字符显示为空白。似乎 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用于汉字?

【问题讨论】:

    标签: c++ qt


    【解决方案1】:

    虽然此嵌入式系统在 X11 上使用 Qt,但解决方案是将字体复制到 /usr/lib/fonts 中,如下所述:

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

    Qt/X11 的集成似乎在这个系统上没有完成。用作基础的 yocto meta-qt5 层默认情况下没有使用此板的 X11。为了使用 X11vnc,它被切换到 X11。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多