[SOLVED] Qt5: Cannot set application font (OTF) from resource
-
wrote on 12 Sept 2014, 17:39 last edited by
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 -
wrote on 12 Sept 2014, 17:57 last edited by
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";
}@ -
wrote on 12 Sept 2014, 18:20 last edited by
can you post the content of the qrc fiile? I thing is a path isue here. did yu tried @:/resources/Mohave.otf@
-
wrote on 12 Sept 2014, 20:13 last edited by
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]
-
wrote on 10 Feb 2015, 09:33 last edited by
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
@ -
wrote on 10 Feb 2015, 09:33 last edited by
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
@ -
wrote on 14 May 2018, 18:59 last edited by
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?
-
wrote on 14 May 2018, 19:26 last edited byThis post is deleted!
-
Hi,
First thing:
addApplicationFont
is a static method. Then you should remove theqrc
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 ?