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. [SOLVED] Qt5: Cannot set application font (OTF) from resource
QtWS25 Last Chance

[SOLVED] Qt5: Cannot set application font (OTF) from resource

Scheduled Pinned Locked Moved General and Desktop
9 Posts 6 Posters 11.0k 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.
  • N Offline
    N Offline
    nando76
    wrote on last edited by
    #1

    Hi,
    i have a problem setting an customized application font, loaded from resource file.

    I added an OTF font to my resource file.

    Then i try to set this font as default application font like this:

    @if(-1 == QFontDatabase::addApplicationFont("qrc:/resources/Mohave.otf"))
    {
    qCritical() << "couldn't add application font";
    }@

    But somehow it does not work.

    The output is:

    @Unable to register font: Error Domain=com.apple.coretext Code=-1 "The operation couldn’t be completed. (com.apple.coretext error -1 - Could not register the font file 'qrc:/resources/Mohave.otf -- file://localhost/development/qtcreator-workspace/test/trunk/TEST-App/')" UserInfo=0x101f24cb0 {NSDescription=Could not register the font file 'qrc:/resources/Mohave.otf -- file://localhost/development/qtcreator-workspace/test/trunk/TEST/', CTFailedFontFileURL=qrc:/resources/Mohave.otf -- file://localhost/development/qtcreator-workspace/test/trunk/TEST/}
    couldn't add application font@

    I am using Mac OS but this font should be used for all devices (Android, iOS...)

    Any ideas?

    Greetings,
    Nando

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nando76
      wrote on last edited by
      #2

      News:

      Somehow without using the Qt resource file like this it works:

      @if(-1 == QFontDatabase::addApplicationFont("resources/Mohave.otf"))
      {
      qCritical() << "couldn't add application font";
      }@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        arsinte_andrei
        wrote on last edited by
        #3

        can you post the content of the qrc fiile? I thing is a path isue here. did yu tried @:/resources/Mohave.otf@

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nando76
          wrote on last edited by
          #4

          That's it ;)
          Thank you!!!

          [quote author="arsinte_andrei" date="1410546027"]can you post the content of the qrc fiile? I thing is a path isue here. did yu tried @:/resources/Mohave.otf@[/quote]

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tycos
            wrote on last edited by
            #5

            I have the same problem:

            @
            if(QFontDatabase::addApplicationFont(":/tex-gyre-adventor.bold.otf") == -1)
            qCritical << "no font loaded";
            @

            output:
            @
            program received signal -111, thread:40e9;qaddr:3c4a1280;00:00000000;01:406nd07;02:f85 ecc ecc
            @

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tycos
              wrote on last edited by
              #6

              I have the same problem:

              @
              if(QFontDatabase::addApplicationFont(":/tex-gyre-adventor.bold.otf") == -1)
              qCritical << "no font loaded";
              @

              output:
              @
              program received signal -111, thread:40e9;qaddr:3c4a1280;00:00000000;01:406nd07;02:f85 ecc ecc
              @

              1 Reply Last reply
              0
              • W Offline
                W Offline
                wesblake
                wrote on last edited by
                #7

                I am having this issue today. I need to use some fonts in my qss. Running Qt 5.7.1.
                Resource entry looks like:

                <RCC>
                    <qresource prefix="/resource">
                        <file>fonts/SF-Pro-Display-Semibold.ttf</file>
                    </qresource>
                    <qresource prefix="/"/>
                </RCC>
                

                I have tried, both in main.cpp and my mainWindow.cpp:

                QFontDatabase fontDB;
                int wtf = fontDB.addApplicationFont("qrc:/resource/fonts/SF-Pro-Display-Semibold.ttf");
                qDebug() << "WTFFONT: "+QString::number(wtf);
                

                And variations of that like without qrc, without :/, etc. Yet every single time I see:

                "WTFFONT: -1"
                

                in the log and the call gives no information at all on why the font was not loaded. I also tried an otf version of the font rom another source. Ideas?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mr Gisa
                  wrote on last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

                    First thing: addApplicationFont is a static method. Then you should remove the qrc and only use :/

                    Did you also try to load that font directly using the full path to it ?

                    By the way, what OS are you running ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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