【報錯】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是否支持在線程中繪製文字。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章