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. QFontDatabase::addApplicationFont return -1
Forum Updated to NodeBB v4.3 + New Features

QFontDatabase::addApplicationFont return -1

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 469 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.
  • A Offline
    A Offline
    achak
    wrote on last edited by
    #1

    My ( first) app on Windows using QT Creator 5.15 . I try load a font from the Google collection.
    I put ttf files into C:/try/gui_0/fonts/SourceSansPro/ folder. Add following line into qrc file:

    <file alias="SSP_Regular.ttf">fonts/SourceSansPro/SourceSansPro-Regular.ttf</file>```
    

    I entered following c++ code into main function:

        int fnt_id = QFontDatabase::addApplicationFont(":/fonts/SourceSansPro/SourceSansPro-Regular.ttf");
        int ali_id = QFontDatabase::addApplicationFont(":/fonts/SourceSansPro/SSP_Regular.ttf");
        int shrt_id = QFontDatabase::addApplicationFont(":/SSP_Regular.ttf");
        int an_id = QFontDatabase::addApplicationFont("SSP_Regular.ttf");
        int qrc_id = QFontDatabase::addApplicationFont("qrc:/fonts/SourceSansPro/SourceSansPro-Regular.ttf");
        int fle_id = QFontDatabase::addApplicationFont("C:/try/gui_0/fonts/SourceSansPro/SourceSansPro-Regular.ttf");
    

    Each line bellow returns -1.
    Whats a problem?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Only the last one can work - the rest is wrong.
      Please make sure that the file is really there and readable

      QFileInfo fi("C:/try/gui_0/fonts/SourceSansPro/SourceSansPro-Regular.ttf");
      if (!fi.exists() || !fi.isReadable()) {
        qWarning() << "Wrong filename";
      } else {
        int fle_id = QFontDatabase::addApplicationFont(fi.absoluteFilePath());
        qDebug() << fle_id ;
      }
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • A Offline
        A Offline
        achak
        wrote on last edited by
        #3

        @Christian-Ehrlicher said in QFontDatabase::addApplicationFont return -1:

        QFileInfo fi("C:/try/gui_0/fonts/SourceSansPro/SourceSansPro-Regular.ttf");
        if (!fi.exists() || !fi.isReadable()) {
        qWarning() << "Wrong filename";
        } else {
        int fle_id = QFontDatabase::addApplicationFont(fi.absoluteFilePath());
        qDebug() << fle_id ;
        }

        Debug output is -1. The font file is exist and readable

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then enable the debug logging for qt.qpa.fonts (see detailed description here: https://doc.qt.io/qt-5/qloggingcategory.html#details ) and see what it prints to your console.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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