failed to load images
literA2 last edited by
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:
view.rootContext()->setContextProperty("imagePath", "file:///" + d.absolutePath + "/images/xhdpi/");
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
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
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:
- added "ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android" in .pro file
- under android folder, i created assets folder and placed the images there
- 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.
assets_catalogs.files = $$files($$PWD/*.xcassets)
QMAKE_BUNDLE_DATA += assets_catalogs
i tried this also:
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.
The path to the iOS assets is
QCoreApplication::applicationPath() + QLatin1String("/../Resources/") + path_to_your_file;