【已解决】QFontDatabase: Cannot find font directory XXX/lib/fonts - is Qt installed correctly?

来源:互联网 发布:淘宝销售数据统计表 编辑:程序博客网 时间:2024/06/06 02:13

【问题】

通过buildroot配置编译好qtopia后下载到开发板上配置好环境变量:

export QWS_DISPLAY="LinuxFb:mmWidth480:mmHeight272:0"
export QWS_SIZE="480x272"
export LD_LIBRARY_PATH=/usr/lib

然后去运行demo程序出现:

# /usr/demos/chip/chip -qws
QFontDatabase: Cannot find font directory /home/crifan/buildroot/buildroot-2009.08/project_build_arm/uclibc/root/usr/lib/fonts - is Qt installed correctly?
Aborted

【解决过程】

1.由于之前已经折腾了关于qtopia的配置并编译所以对于qt的官方的文档中的这部分说明:

http://qt.nokia.com/doc/qtopia4.3/running-qtopia.html

“Environment Settings to Run Qtopia

There are no specific environment variables required to run Qtopia, however there are some that can be set to control Qtopia's features.

If you specified -no-rpath you will need to set LD_LIBRARY_PATH so that the libraries can be found.

Qtopia does not require PATH to be set but third party applications may expect it to include <prefix>/bin.

You may wish to set some environment variables to configure Qtopia Core. You may also need to set QTOPIA_PHONE_DEVICE. SeeQtopia Environment Variables for details on how to set environment variables.

应该还算理解了其意思说的是如果你当初编译qtopia的时候在./configure 中加了-no-rpath根据说明:

“    -no-rpath .......... Do not use the library install path as a runtime
                         library path.
+ -rpath ............. Link Qt libraries and executables using the library
                         install path as a runtime library path. Equivalent
                         to -R install_libpath

意思就是不要使用你的安装路径即-prefix指定的路径如果没用-prefix指定那么就是默认的/usr/local/Trolltech/QtEmbedded-4.5.3:
“    -prefix <dir> ...... This will install everything relative to <dir>
                         (default /usr/local/Trolltech/QtEmbedded-4.5.3)”

而我这里当初配置的是-prefix $(TARGET_DIR)/usr,即 -prefix /home/crifan/buildroot/buildroot-2009.08/project_build_arm/uclibc/root/usr意思是将qtopia安装到buildroot中rootfs中的usr下面。

并且按照其说明不需要配置其他环境变量了只是由于编译的时候加了-no-rpath所以需要配置一下对应的LD_LIBRARY_PATH这里由于之前配置成/home/crifan/buildroot/buildroot-2009.08/project_build_arm/uclibc/root/usr,buildroot中make的时候编译qt并make install到对应的rootfs文件夹的usr下面了而现在rootfs已经烧写到板子了已经进了rootfs了所以要配置成/usr/lib以便qt程序运行的时候能找到对应的库文件。

所以其他参数应该就没有再需要配置的了应该就可以工作的了。

而且关于

http://qt.nokia.com/doc/qtopia4.3/qtopiacore-envvars.html

也介绍了关于qt-core的一些环境变量主要是QWS_DISPLAY我这里也按照网上别人的帖子和官方文档中的说明去配置了:

export QWS_DISPLAY="LinuxFb:mmWidth480:mmHeight272:0"
export QWS_SIZE="480x272"

export QWS_DISPLAY="LinuxFb:/dev/fb0"
但是还是无法工作运行测试程序还是显示错误:

# /usr/demos/mainwindow/mainwindow -qws
QFontDatabase: Cannot find font directory /home/crifan/buildroot/buildroot-2009.08/project_build_arm/uclibc/root/usr/lib/fonts - is Qt installed correctly?

最后无意间在网上看到别人的帖子:

http://hi.baidu.com/a263238386/blog/item/6ff055dda933033e5882dd32.html

发现有个关于qt font的环境变量:export QT_QWS_FONTDIR=$QTDIR/lib/fonts

所以自己就去加了一下:

export QT_QWS_FONTDIR=/usr/lib/fonts

export LD_LIBRARY_PATH=/usr/lib
或者

export QTDIR=/usr
export LD_LIBRARY_PATH=$QTDIR/lib
export QT_QWS_FONTDIR=$QTDIR/lib/fonts

结果qt的demo程序就可以运行了呵呵。

总结一下解决方法就是:

正确设置QT_QWS_FONTDIR,指定qt的font具体路径这样程序才能找到font

此处我的是

export QT_QWS_FONTDIR=/usr/lib/fonts

实际结果表明这些相关的qt的环境变量是必须的要指定好对应的位置让qt能找到qt的lib和font等必须的资源才可以运行qt的demo和example的。

其他的参数好像这个可有可无的:

export QT_PLUGIN_PATH=$QTDIR/plugins/

如果用到鼠标和键盘那估计

http://qt.nokia.com/doc/qtopia4.3/qtopiacore-envvars.html

中的QWS_MOUSE_PROTO和QWS_KEYBOARD 也要配置好的。有空再去试试。

【提示】

1.关于-prefix参数为何不用qt默认的配置的/usr 而去自己修改为$(TARGET_DIR)/usr

因为默认的qt.mk中原先配置的是 -prefix /usr,会去讲qtopia安装到我buildroot所在Linux的/usr下面很弱智的这样你buildroot中去make最后的qtopia的make install会去将生成的qt的东西用于arm板子的qt的东西会安装到你当前X86的PC上的Linux下的/usr这不扯淡的吗。。

所以才会去在buildroot中package/qt.mk中配置成QT_CONFIGURE += -prefix $(TARGET_DIR)/usr

【引用】

1。Online Reference Documentation

http://qt.nokia.com/doc/qtopia4.3/index.html

2.Qtopia Developer Resources

http://qt.nokia.com/doc/qtopia4.3/index.html

3.Running Qtopia
http://qt.nokia.com/doc/qtopia4.3/running-qtopia.html

4.Qtopia Core Environment Variables
http://qt.nokia.com/doc/qtopia4.3/qtopiacore-envvars.html

5.QT 4.5.2 嵌入式开发平台的搭建

http://hi.baidu.com/a263238386/blog/item/6ff055dda933033e5882dd32.html

6.环境变量QWS_DISPLAY

http://fanzhichao.blog.hexun.com/23669000_d.html

原创粉丝点击