Qt 5.9.1 static, font problem on Linux
-
wrote on 7 Jul 2017, 13:19 last edited by
Hi all,
I built static Qt 5.9.1 using:./configure -release -static -prefix /opt/qt591_static -skip qtwebengine -nomake tests -nomake examples make make install
I can compile a simple Qt App but when I run it I get:
QFontDatabase: Cannot find font directory /opt/qt591_static/lib/fonts. Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.
Can someone explain me why?
Should I embed Font? -
wrote on 28 Jul 2019, 21:48 last edited by
This is happening because Qt 5 no longer ships with fonts embedded, and since you are using a static version, it does not find the font files it would otherwise would (as part of the dynamic/shared library distribution).
You have three options:a) Embed fonts as resources in your application, as suggested in this StackOverflow post:
https://stackoverflow.com/questions/20751604/static-qt5-build-on-linux-how-to-handle-fonts-when-deploying
The code is:QGuiApplication app(argc, argv);
QQuickView view;// Load the embedded font.
QString fontPath = ":/fonts/MyFont.ttf";
int fontId = QFontDatabase::addApplicationFont(fontPath);
if (fontId != -1)
{
QFont font("MyFont");
app.setFont(font);
}b) Do what the error message suggests and install fonts in the directory indicated. This is impractical for distributing your application, it will only work on your computer.
c) Recompile the static version of Qt to use fontconfig. In order to do that you have to pass the following options to configure:
./configure (...other options...) -fontconfig -system-freetype (...other options)
Note that you'll have to use the system's freetype installation (i.e. you cannot combine -fontconfig with -qt-freetype). So make sure you have the development libraries for freetype installed:
sudo apt-get install libfontconfig1-dev