QML FontLoader: Cannot load font
-
Hello
I can't for the life of me, get the FontLoader to work. I have tried following the documentation, but it still doesn't work.
I am making an app for Android.The .ttf is in the same folder as the project files (./Lato-Regular.ttf).
FontLoader is a component of Window (root). Button is a component of a Grid, that is a component of Window.I have also tried adding the .ttf to a .qrc file, but I get the same error, even when using "qrc:/x"
FontLoader { id: customfont source: "Lato-Regular.ttf" } Button { id: requestItemButton width: 250 height: 150 antialiasing: true Material.roundedScale: Material.NotRounded contentItem: Text { text: "Request Items" font: customfont.font color: "#CE0F69" //#800080 //"#920092" //font.pixelSize: 20 antialiasing: true horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } }
-
Hi and welcome to devnet,
Your executable is not in the same folder as your sources so using a relative path won't work.
As for usingqrc:
did you create a proper Qt resource to make use of it ? -
This post is deleted!
-
@CodeBroker
Could you show your actualFontLoader
code when using a resource, please? -
FontLoader { id: customfont source: ":/Lato-Regular.ttf" }
Error: E libappKioskapp_x86_64.so: "illegal value"
W libappKioskapp_x86_64.so: qrc:/Kioskapp/Main.qml:21:5: QML FontLoader: Cannot load font: "qrc:/Kioskapp/:/Lato-Regular.ttf"FontLoader { id: customfont source: "qrc:/Lato-Regular.ttf" }
Error: E libappKioskapp_x86_64.so: "illegal value"
W libappKioskapp_x86_64.so: qrc:/Kioskapp/Main.qml:21:5: QML FontLoader: Cannot load font: "qrc:/Lato-Regular.ttf" -
@CodeBroker
So (not my area, never used resources) clearly:/...
is not the way to do it.qrc:/...
looks better. You useqrc:/Lato-Regular.ttf
here, but earlier you said you were going to use/it has been added asqrc:/Fonts/...
, so perhaps you need that here? What is the actual path to the embedded font in the resources? From C++ code you can useQFile::exists("...")
to check whether a resource file exists. I'm not sure whether that expects:/...
orqrc:/...
syntax. -
@JonB I have tried multiple paths, none of them work. I use qrc:/ when using icons, and that works fine; but I have added them in the cmakelists.txt. I find no resources that tells me to put any font path in cmakelists.txt, and neither do I know how to add them.
-
@CodeBroker
That I don't know, as I don't use resources or cmake. But if cmakelists.txt does include something for icon resources but nothing for font resources that does not sound right, maybe the runtime failures are because the font is not actually embedded. -