picture locations
-
So, I am reading through the PDF book about QML and have got to the point where a triangle, box and circle picture are used.
the image addresses fail to load any image. I actually tried searching for the image files but didn't come up with anything. So I created my own and put them in the same folder as the QML files, still they fail to load.
I have looked this up and find that I am not alone, but the answers range from, "just put the path to the files relative or absolute" to needing to set something up that I am not yet familiar with.
So, what do I do?
-
Hi,
Which book would that be ?
Which example ?
Usually, for application images, the Qt Resource system is used to embed the files in the binary. -
https://www.qt.io/product/qt6/qml-book
Page 89: Simple Transformations
This cade does not work, it throws errors like: QML ClickableImage: Cannot open: qrc:/qt/qml/Qt_Quick_Application/img/triangle.png
that address does not exist, at least the qrc:/qt/qml/ is new to me. -
@Groundbounce
I have not look at the book. But do you understand that a "path" starting withqrc:
means that it is an embedded Qt resource file, as per @SGaist above? You will not find that as an external file in your actual file system, rather you will have designed it to be embedded in your executable. Which I can only presume the book will have shown you. -
I am vaguely aware of the resource file after I started looking into the issue. I still have not found enough information to set things up. No the book says nothing about the resource system.
-
The resources chapter in the documentation is there to help you.
-
Is there anything else I am supposed to do other than create the resources file that links the pictures?
-
I have set it up from scratch. This is my main.qml code:
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")Image { source: "://triangle.png" }
}
There is no longer an error when I run it saying that it cannot load the image. but the window is empty.
-
Well I got it to work, regrettably the revered manual is a steaming pile of.........! assuming what I did is right as every person on YouTube has a different way of doing it.....
-
What did you do to fix your issue ?
-
There was a similar question the other day and this was what I said:
I recall having to try a few things when I first wanted to do this a few years ago. I don't know if what I arrived at is the "correct" approach, but the format that I found to work in QML and have stuck to ever since involves using a triple forward slash like this:
source: "qrc:///images/my-image.png"
As it's something that keeps popping up, I'd be interested to see some clarification on this from experts. I don't know if QML introduces any quirks above and beyond what is described in the resources chapter in the docs, which does not explicitly mention QML.