天天看点

【报错】ubuntu下qt无法加载字体库

ubuntu下使用qt4.8.6,使用addApplicationFont加载字体库失败,该字体库在windows下能够正常加载使用,排除是字体库的原因,查看帮助文档addApplicationFont的函数说明,上面说unix需要支持fontconfig。

Loads the font from the file specified by fileName and makes it available to the application. An ID is returned that can be used to remove the font again with removeApplicationFont() or to retrieve the list of family names contained in the font.
The function returns -1 if the font could not be loaded.
Currently only TrueType fonts, TrueType font collections, and OpenType fonts are supported.
Note: Adding application fonts on Unix/X11 platforms without fontconfig is currently not supported.
Note: On Symbian, the font family names get truncated to a length of 20 characters.
This function was introduced in Qt 4.2.
           

网上一查,配置qt源码的时候需要配置fontconfig。即./configure -fontconfig。如果报错FontConfig support cannot be enabled, due to functionality tests!

则安装apt-get install libfontconfig1-dev。然后重新编译源码即可。即make→sudo make install。重新编译完之后就可以用了。

没有配置fontconfig,还会出现在线程中无法drawText的问题,绘制的文字显示一个个矩形框,可以通过查看supportsThreadedFontRendering是否支持在线程中绘制文字。

继续阅读