1

I have a problem trying to load an image from an absolute path from qml. (from a relative path everything goes well)

Image {
    id : myimage

    source: qsTr("qrc:///")+imagePath
}

My image path is a well defined windows path. I tried many suggestions that I found while googling:
Like starting with file:/// or with qrc:///
Nothing I found worked. It can not load the image.

Is there something I am missing here?

James Risner
  • 5,451
  • 11
  • 25
  • 47
Josh.h
  • 71
  • 1
  • 13
  • 1
    Side note: You do not need to use qsTr() around "qrc:///". That string shouldn't need to change languages. – JarMan Sep 21 '22 at 14:13
  • 1
    Only use "qrc:///" if your image is coming from a resource file. For files coming from the filesystem use "file:///". *"my image path is a well defined windows path"* -- Can you be more specific? What exactly are you trying to set imagePath to? Without seeing the real string, we can't tell if there is a mistake in it. – JarMan Sep 21 '22 at 14:18

1 Answers1

1

The absolute path you'll want to be using is formatted as a URI like documented here: Windows File URI

Try something like: source: "file:///c:/mypath/myimage.png"

bwoj
  • 26
  • 3