QFontDatabase: Cannot find font directory

在银河麒麟操作系统上编译Qt程序时遇到QFontDatabase报错,原因是Qt安装目录缺少字体。解决方法是将Windows字体库复制到Qt的lib/fonts目录或系统字体目录,例如/usr/share/fonts,并在环境变量中设置QT_QPA_FONTDIR。如果磁盘空间有限,可以只拷贝必要的字体以节省空间。

现象:

今天在银河麒麟操作系统上编译Qt 写的程序,报如下 错误:

QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
QFontDatabase: Cannot find font directory /home/tgm/qt/qt_sdk/lib/fonts.
Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.

分析原因:这是因为Qt安装目录下没有字体文件导致的,我的Qt安装目录为:

/usr/local/Qt 5.9.2

字体目录一般在Qt安装目录下的lib/fonts下即:

/usr/local/Qt 5.9.2/lib/fonts

解决方法:

找一个安装了windows操作系统的机器,将其字体库(一般在C:\Windows\Fonts目录下,有的还很大,几百兆吧)拷贝到/usr/local/Qt 5.9.2/lib/fonts目录或者系统字体目录,如:我的银河麒麟操作系统字体存放目录为:

/usr/share/fonts

然后执行:

sudo vim /etc/profile

在其后加入如下代码:


export QT_QPA_FONTDIR=/usr/share/fonts

/usr/local/Qt 5.9.2/lib/fonts

重启系统即可。

注意:windows下的字体库很大,我的444MB,对于嵌入式的、磁盘空间有限的情况,请根据你要的字体进行删减,以节约空间。

To restore this content, you can run the 'unminimize' command. Last login: Thu Jun 5 05:44:30 2025 from 192.168.3.102 ys@tegra-ubuntu:~$ export QT_QPA_PLATFORM=eglfs ys@tegra-ubuntu:~$ export QT_EGLFS_ALWAYS_SET_MODE=1 ys@tegra-ubuntu:~$ export QT_QPA_EGLFS_INTEGRATION=none ys@tegra-ubuntu:~$ ./untitled Device discovery cannot open device "/dev/input/event0" Device discovery cannot open device "/dev/input/event1" Device discovery cannot open device "/dev/input/event2" Device discovery cannot open device "/dev/input/event3" Device discovery cannot open device "/dev/input/event4" Device discovery cannot open device "/dev/input/event5" Device discovery cannot open device "/dev/input/event6" Device discovery cannot open device "/dev/input/event0" Device discovery cannot open device "/dev/input/event1" Device discovery cannot open device "/dev/input/event2" Device discovery cannot open device "/dev/input/event3" Device discovery cannot open device "/dev/input/event4" Device discovery cannot open device "/dev/input/event5" Device discovery cannot open device "/dev/input/event6" Device discovery cannot open device "/dev/input/event0" Device discovery cannot open device "/dev/input/event1" Device discovery cannot open device "/dev/input/event2" Device discovery cannot open device "/dev/input/event3" Device discovery cannot open device "/dev/input/event4" Device discovery cannot open device "/dev/input/event5" Device discovery cannot open device "/dev/input/event6" QFontDatabase: Cannot find font directory /usr/local/qt-for-arm5.15.15/lib/fonts. Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig. QFontDatabase: Cannot find font directory /usr/local/qt-for-arm5.15.15/lib/fonts. Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig. QFontDatabase: Cannot find font directory /usr/local/qt-for-arm5.15.15/lib/fonts. Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig. QFontDatabase: Cannot find font directory /usr/local/qt-for-arm5.15.15/lib/fonts. Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig. QFontDatabase: Cannot find font directory /usr/local/qt-for-arm5.15.15/lib/fonts. Note that Qt no longer ships fonts. Deploy some (from https://dejavu-fonts.github.io/ for example) or switch to fontconfig. EGL Error : Could not create the egl surface: error = 0x300b 报错
最新发布
06-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值