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. failed to load images
Qt 6.11 is out! See what's new in the release blog

failed to load images

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 2 Posters 3.0k 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.
  • L Offline
    L Offline
    literA2
    wrote on last edited by
    #1

    Hi,

    I am trying to deploy my app into mobile device however the images cannot be loaded because I didn't include them in resource file.

    Please advise where should I put the images, i did these while running only on desktop:

    @
    QDir d;
    view.rootContext()->setContextProperty("imagePath", "file:///" + d.absolutePath + "/images/xhdpi/");
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You have to embed the files in your package. For example, on Android you can use what they call Assets

      Hope it helps

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

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You have to embed the files in your package. For example, on Android you can use what they call Assets

        Hope it helps

        L Offline
        L Offline
        literA2
        wrote on last edited by literA2
        #3

        @SGaist thanks for the reply.

        That is what i am thinking also because based on the error message it can't find the images into file file://data/data/xxx/files/assets location.

        Should this be different in ios, i guess.

        Can you please advise how to do it? Thanks

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You should rather use QStandardPaths to retrieve the correct path to your files. file://data is not valid at all in the mobile world.

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

          L 1 Reply Last reply
          0
          • SGaistS SGaist

            You should rather use QStandardPaths to retrieve the correct path to your files. file://data is not valid at all in the mobile world.

            L Offline
            L Offline
            literA2
            wrote on last edited by literA2
            #5

            @SGaist can you please provide an example on how to use QStandardPaths ?

            And also how to embed the images into the package. Thanks

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              iOS deployment guide

              My bad, you don't need QStandardPaths to access the resources. You can use:

              QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/") + your_resource_path
              

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

              L 1 Reply Last reply
              0
              • SGaistS SGaist

                iOS deployment guide

                My bad, you don't need QStandardPaths to access the resources. You can use:

                QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/") + your_resource_path
                
                L Offline
                L Offline
                literA2
                wrote on last edited by literA2
                #7

                @SGaist Thanks for the reply.

                However, I managed to resolved the issue on Android by these steps:

                1. added "ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android" in .pro file
                2. under android folder, i created assets folder and placed the images there
                3. then used "assets:/filename.png" to get the images.

                I am having problem now in ios. I tried creating assets catalog based from the link you provided, however i'm having problem how to call the images or path to use.

                @
                ios {
                assets_catalogs.files = $$files($$PWD/*.xcassets)
                QMAKE_BUNDLE_DATA += assets_catalogs
                }
                @

                i tried this also:

                @
                ios {
                imageResource.files =images/*.png
                QMAKE_BUNDLE_DATA += imageResource
                }
                @

                it is trying to find the images from qrc:/qml/ directory however, i didn't include the images into resource file. Once i open the app package, images folder is located on main directory.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  The path to the iOS assets is QCoreApplication::applicationPath() + QLatin1String("/../Resources/") + path_to_your_file;

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

                  1 Reply Last reply
                  0

                  • Login

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