failed to load images

  • 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/");

  • Lifetime Qt Champion


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

    Hope it helps

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

  • Lifetime Qt Champion

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

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

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

  • Lifetime Qt Champion

    iOS deployment guide

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

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

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

  • Lifetime Qt Champion

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

Log in to reply

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