Important: Please read the Qt Code of Conduct -

Referencing image files in Android

  • I have a problem when referencing files in Android. I need to open images both in my C++ and QML part.

    On desktop I can use QUrl::fromLocalFile() in C++ and Qt.resolvedUrl() in QML and it works for both relative paths (to a subfolder in QML directory) and absolute path anywhere on the drive.

    On Android it won't work nor for the relative neither absolute path.

    Is there any universal solution for all systems and both relative and absolute paths?

  • I solved the problem at QML side but I still can not find my files in C++ code. I can locate it on desktop using the path "qml/MyApp/images/image.jpg". But on Android using this path doesn't work. Do you have any idea what should be the correct path in Android? Thank you.

  • Lifetime Qt Champion


    What kind of files are we talking about here ? Your application own resources ?

  • Yes. I solved it using the resource system (adding them to a .qrc file) because this seems to be the only reliable cross platform solution. I didn't want to do that because I include the whole QML directory with all subdirectories (containing pictures) anyway. And I wanted to be able to change these pictures.

    But I was not able to figure out how to open a picture based on a relative path on Android. Probably it is because on Android the files are not stored relative to the executable but in another directory.

  • Lifetime Qt Champion

    You also have the Android assets alternative.

  • Thank you. I will have a look at it. But I'll probably stay with the resource system as it is cross platform.

  • Lifetime Qt Champion

    As you wish :)

    In any case, since you have it working now, please mark the thread as solved using the "Topic Tools" so that other forum users may know a solution has been found :)

Log in to reply