Can't load Image source in QML Image

后端 未结 6 925
小鲜肉
小鲜肉 2021-02-07 03:08

This seems really basic but for some reason I can\'t get the image source to work in the ultra-simple QML app below.

FYI, I\'m running Mac OS-X 10.9.5, Qt Creator 3.2.

相关标签:
6条回答
  • 2021-02-07 03:29

    I suppose that your qml file is in resources, so try place your testImage.png image in resources too. Recompile app, run it and check is image works properly.

    All should be together. For example:

    enter image description here

    My code:

    Image
    {
        source: "images/earth.png"
    

    If I delete this image from resources, I'll get this error too, but image still in the correct place in file system.

    When qml source placed in the resource, then all files, which loads from qml should be in resource too (Qt searchs this files in the resources, not in the file system).

    0 讨论(0)
  • 2021-02-07 03:33

    If you are using qrc, make sure the image is added to your project. Just having it in your source directory may not be enough. For example, my main.qml is located in a particular directory. I move my .png into the same directory. I then "Add Existing Files.." and add the .png to the project. My image has the following

    source:"qrc:<same dir as main.qml>/image.png"
    
    0 讨论(0)
  • 2021-02-07 03:34

    Try to close Shadow Build under Projects->Build Settings.

    0 讨论(0)
  • If you are locating from local filesystem , get the file path and prefix "file:" as source = "file:/root/Desktop/Rathod.png"

    0 讨论(0)
  • 2021-02-07 03:37

    There can be two problems:

    1. The image is corrupt, although the image was correctly displayed in all previews IconImage refuses to load it. Try to use another image that is known as work correctly It seems that the Qt Image loader is very sensitive to the image format.
    2. There is a resource cache problem. Try to delete qml_qmlcachea.qrc in your compiling folder and try it again
    0 讨论(0)
  • 2021-02-07 03:50

    I had a similiar problem and solved it the following way:

    1. Right click on your qml.qrc, then choose "open with" -> "Resource Editor"
    2. Once you are in the Resource Editor click on "Add missing file", there choose your image
    3. Lastly open your qml file in the Design editor and click on the Image element, on the right side choose the path to the image
    0 讨论(0)
提交回复
热议问题