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



  • 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



  • 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";
    }@



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



  • 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]



  • 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
    @



  • 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
    @



  • 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?



  • This post is deleted!

  • Lifetime Qt Champion

    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 ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.