Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML FontLoader: Cannot load font
Forum Updated to NodeBB v4.3 + New Features

QML FontLoader: Cannot load font

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 4 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CodeBroker
    wrote on 17 Jul 2023, 12:38 last edited by
    #1

    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
                }
            }
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 17 Jul 2023, 13:22 last edited by
      #2

      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 using qrc: did you create a proper Qt resource to make use of it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply 17 Jul 2023, 13:26
      0
      • S SGaist
        17 Jul 2023, 13:22

        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 using qrc: did you create a proper Qt resource to make use of it ?

        C Offline
        C Offline
        CodeBroker
        wrote on 17 Jul 2023, 13:26 last edited by
        #3

        @SGaist Hello and thanks :). I used Qt Creator to create a resource file, and added the font file to it via the GUI. i.e "qrc:/Fonts/myfont.ttf"

        L J 2 Replies Last reply 17 Jul 2023, 13:32
        0
        • C CodeBroker
          17 Jul 2023, 13:26

          @SGaist Hello and thanks :). I used Qt Creator to create a resource file, and added the font file to it via the GUI. i.e "qrc:/Fonts/myfont.ttf"

          L Offline
          L Offline
          lemons
          wrote on 17 Jul 2023, 13:32 last edited by lemons
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • C CodeBroker
            17 Jul 2023, 13:26

            @SGaist Hello and thanks :). I used Qt Creator to create a resource file, and added the font file to it via the GUI. i.e "qrc:/Fonts/myfont.ttf"

            J Offline
            J Offline
            JonB
            wrote on 17 Jul 2023, 14:00 last edited by
            #5

            @CodeBroker
            Could you show your actual FontLoader code when using a resource, please?

            C 1 Reply Last reply 18 Jul 2023, 06:56
            0
            • J JonB
              17 Jul 2023, 14:00

              @CodeBroker
              Could you show your actual FontLoader code when using a resource, please?

              C Offline
              C Offline
              CodeBroker
              wrote on 18 Jul 2023, 06:56 last edited by
              #6

              @JonB

              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"

              J 1 Reply Last reply 18 Jul 2023, 07:19
              0
              • C CodeBroker
                18 Jul 2023, 06:56

                @JonB

                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"

                J Offline
                J Offline
                JonB
                wrote on 18 Jul 2023, 07:19 last edited by JonB
                #7

                @CodeBroker
                So (not my area, never used resources) clearly :/... is not the way to do it. qrc:/... looks better. You use qrc:/Lato-Regular.ttf here, but earlier you said you were going to use/it has been added as qrc:/Fonts/..., so perhaps you need that here? What is the actual path to the embedded font in the resources? From C++ code you can use QFile::exists("...") to check whether a resource file exists. I'm not sure whether that expects :/... or qrc:/... syntax.

                C 1 Reply Last reply 18 Jul 2023, 07:42
                0
                • J JonB
                  18 Jul 2023, 07:19

                  @CodeBroker
                  So (not my area, never used resources) clearly :/... is not the way to do it. qrc:/... looks better. You use qrc:/Lato-Regular.ttf here, but earlier you said you were going to use/it has been added as qrc:/Fonts/..., so perhaps you need that here? What is the actual path to the embedded font in the resources? From C++ code you can use QFile::exists("...") to check whether a resource file exists. I'm not sure whether that expects :/... or qrc:/... syntax.

                  C Offline
                  C Offline
                  CodeBroker
                  wrote on 18 Jul 2023, 07:42 last edited by
                  #8

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

                  J 1 Reply Last reply 18 Jul 2023, 07:46
                  0
                  • C CodeBroker
                    18 Jul 2023, 07:42

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

                    J Offline
                    J Offline
                    JonB
                    wrote on 18 Jul 2023, 07:46 last edited by
                    #9

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

                    C 1 Reply Last reply 18 Jul 2023, 10:42
                    0
                    • J JonB
                      18 Jul 2023, 07:46

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

                      C Offline
                      C Offline
                      CodeBroker
                      wrote on 18 Jul 2023, 10:42 last edited by
                      #10

                      @JonB That's what I suspect, but if that were the case, I would expect to find a lot more people sharing my issue, as the documentation doesn't mention it.

                      1 Reply Last reply
                      0
                      • C CodeBroker has marked this topic as solved on 20 Jul 2023, 11:56

                      1/10

                      17 Jul 2023, 12:38

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved