Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 5.9.1 static, font problem on Linux
Forum Updated to NodeBB v4.3 + New Features

Qt 5.9.1 static, font problem on Linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      porcupinebrux
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved