I'm writing an Ubuntu QML (phone) App with C++ plugins using ubuntu-sdk. My app includes a png image and in order to include the image in the binary (so it shows on the phone) I have created a qrc file.

My qrc file looks like this:

<!DOCTYPE RCC><RCC version="1.0">

I've tried what QML app with C++ plugin (cmake) adding resource file suggests and got the Desktop version to work. However, when I run the app on my Aquaris E4.5 the image doesn't show up and I get the following error:

QML QQuickImage: Cannot open: file:///opt/click.ubuntu.com/ProjectName.Nickname/0.1/share/qml/app/graphics/bigredbutton.png

The image I want to show is stored in the /ProjectName/app/graphics directory. I'm including the qrc file within the backend directory, and added the lines the linked question indicates in the CMakeLists.txt within the backend directory:

qt5_add_resources(RESOURCES modules/ProjectName/myres.qrc)

Where should the image/qrc files be stored, or what other configuration is necessary for packing the image in the binary and launching the app successfully on an Ubuntu Phone?

I'm on Ubuntu 15.10 using the latest ubuntu-sdk version.

  • I ended up creating a qmake project instead of a cmake project and achieved embedding the image in the binary. For my needs that's OK, since I'm just developing a simple proof-of-concept app. However if anyone has info on how to do the same with cmake it might be helpful for others in the future. – koukouviou Dec 17 '15 at 10:44
  • Hey koukouviou, I've got a question that I've now placed a 50 point bounty on: askubuntu.com/questions/777348/… I've referenced your comment about embedding the image in the binary which would appear to be what I need to do, so if you happen to know the answer, then there's a +50 reputation in it for you :) – pHeLiOn Jun 6 '16 at 16:03

This is what worked for me.
My resources.qrc is in {PROJECT_DIR}/resources:

    <qresource prefix="/180">
        <file alias="five">180/five_180.png</file>

In my backend/CMakeLists.txt I have:

qt5_add_resources(RESOURCE_ADDED ${CMAKE_SOURCE_DIR}/resources/resources.qrc)
add_library(Projectnamebackend MODULE
add_custom_target(Projectnamebackend-qmldir ALL
    COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/modules/Projectname/qmldir ${CMAKE_CURRENT_BINARY_DIR}/Projectname

I can then use the images in a .cpp-file like this:

m_image = QImage(":/180/one");

The project has the default example-app structure, given by the IDE.
I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.