1
votes

Im trying to add an image to my qml project and show it. The image part:

Image {
    id:menuLogo
    width:400
    height:400
    source: "design/logo.png"
}

My project structure. The filename is even suggested when typing the first part of the path in qt.

enter image description here

The error I get when running the code:

qrc:/Menu.qml:9:5: QML Image: Cannot open: qrc:/design/logo.png

1

1 Answers

4
votes

By default QML searches for the resources in the .qrc, but in your case the image is not there. So a possible solution is to add it to the qml.qrc that you have for it, follow the following steps:

  1. Right click on qml.qrc and select "Add Existing Files ..".
  2. Select the images that are in the design folder.
  3. Compile again.

Another option is to pass the local url:

Image {
    id:menuLogo
    width:400
    height:400
    source: file:///path/of/logo.png
}