Important: Please read the Qt Code of Conduct -

Qt 5.9.1 static, font problem on Linux

  • Hi all,
    I built static Qt 5.9.1 using:

    ./configure -release -static -prefix /opt/qt591_static -skip qtwebengine -nomake tests -nomake examples
    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 for example) or switch to fontconfig.

    Can someone explain me why?
    Should I embed Font?

  • 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:
    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");

    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

Log in to reply