[Solved] Fonts won't load on iOS but loads on Android



  • Hey!
    I'm currently loading two fonts from a qrc file. One of them is .ttf and the other is .otf. When I test my build on Android, they load and work fine (although the loading time is fairly long..)

    However when I test it on my iPhone and/or simulator, none of the fonts load at all. They just seem to default back to Arial or something. Furthermore, only the .otf file works fine on Windows. The .ttf file defaults back to Arial and the characters are offset by 2 characters (so the word "ok" would be "qm")

    What the hell is going on?
    The fonts are located in:
    "qrc:/fnt/res/fnt/MuseoSans_500.otf"
    "qrc:/fnt/res/fnt/museo100-regular.ttf"

    and I'm using this to load the fonts:

        FontLoader {
            id: museosans500
            source: "qrc:/fnt/res/fnt/MuseoSans_500.otf"
        }
    
        FontLoader {
            id: museo100
            source: "qrc:/fnt/res/fnt/museo100-regular.ttf"
        }
    

    I'm using Qt Creater 3.4.0 and Qt 5.4.1

    When accessing the fonts I set the font.family to museosans500.name and museo100.name. Like I said, they work fine on Android. But neither work on iOS, and only one of them works on Windows.

    Any help is much appreciated!



  • One problem could be the order of calls. You need to have loaded all fonts before any widget is created, but after the Qt application object has been created. We had a similar problem with fonts and solved it by loading it in c++ before launching the main qml file.

    With the wrong order, the behaviour is undefined. It could work, but it is not guaranteed to.



  • @cybercatalyst Hey thanks for your reply!

    So I've tried a couple of things with no luck.
    First one was not loading any QML objects requiring the font until the FontLoader had finished loading fonts (so waited until status == FontLoader.Ready, which SHOULD mean the fonts were loaded successfully, right?). Results didn't change. Both fonts still worked on Android, just one worked on Windows and none worked on iOS.

    Then I used QFontDatabase to load the files in through main.cpp before any QML was even launched. Strangely enough Windows was unaffected, still displaying only one font correctly. However, Android failed to load any fonts and iOS remained the same. The strange thing is I check for errors when loading fonts and all of them are apparently loading in just fine?

    This one really has my scratching my head!



  • Well that was interesting.
    I printed all of the font families to console from all of the platforms.
    For Windows it prints them as "Museo Sans 500" and "Museo 100". Only Museo Sans 500 actually works though. Museo 100 renders incorrectly.
    On Android, Mac and iOS they print out as "Museo Sans" and "Museo" respectively. When I changed to C++ loading and altered the QML font.family to use "Museo Sans" and "Museo" as the source they worked completely fine on Android, Mac and iOS.
    It didn't load on Windows, but since this application is for Android and iOS I thankfully don't need it to work properly on Windows anyway.

    Hope this helps anyone struggling with the same issue!



  • Just because a font shows up to be available doesn't mean it's loaded correctly. Can you paste you main.cpp here?



  • @cybercatalyst Oh okay. I was under the impression that if it didn't return -1 it was a successful load.

    My main.cpp is as follows:

    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        // Load custom fonts
        if(QFontDatabase::addApplicationFont(QStringLiteral(":/fnt/res/fnt/MuseoSans_500.otf")) == -1)
        qDebug() << "Failed to load font Museo Sans 500";
        if(QFontDatabase::addApplicationFont(QStringLiteral(":/fnt/res/fnt/museo100-regular.ttf")) == -1)
        qDebug() << "Failed to load font Museo 100";
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/res/qml/LoadScreen.qml")));
    
        return app.exec();
    }


  • This is correct. This will be most likely a Windows-related problem with the ttf font.


Log in to reply
 

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