[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 -
can you post the content of the qrc fiile? I thing is a path isue here. did yu tried @:/resources/Mohave.otf@
-
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?
-
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 ?