picture locations
-
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.
-
I don't understand why something so essential is such a mystery. The documentation page presents a sample fise:
[code]
<RCC>
<qresource prefix="/">
<file>images/copy.png</file>
<file>images/cut.png</file>
<file>images/new.png</file>
<file>images/open.png</file>
<file>images/paste.png</file>
<file>images/save.png</file>
</qresource>
</RCC>
[/code]It then proceeds to say, one would assume with reference to the above:
The Qt Resource System
The Qt resource system is a platform-independent mechanism for shipping resource files in an application. Use it if your application always needs a certain set of files (like icons, translation files, images), and you don't want to use system-specific means to package and locate these resources.Most commonly, the resource files are embedded into your application executable, or in libraries and plugins that are loaded by the application executable. Alternatively, the resource files can also be stored in an external resource file.
The resource system is based on tight cooperation between Qt's rcc resource compiler, the build system, and the Qt runtime API.
Note: Currently, the Qt resource system does not make use of any system-specific capabilities for handling resources, such as the ones on Windows, macOS, and iOS. This might change in a future Qt release.
The Qt Resource Compiler (rcc)
The Resource Compiler (rcc) command line tool reads resource files and generates either a C++ or Python source file, or an .rcc file.The list of files and related metadata is passed to rcc in the form of a Qt Resource Collection File.
By default, rcc will generate C++ source code that is then compiled as part of an executable or library. The -g python option generates Python source code instead. The -binary option generates a binary archive that is by convention saved in an .rcc file and can be loaded at runtime.
Note: While it is possible to run rcc from the command line, this is typically best left to a build system. See also the sections about qmake and CMake below.
Qt Resource Collection File (.qrc)
A .qrc file is an XML document that enumerates local files to be included as runtime resources. It serves as input to rcc.Here's an example .qrc file:
<RCC>
<qresource prefix="/">
<file>images/copy.png</file>
<file>images/cut.png</file>
<file>images/new.png</file>
<file>images/open.png</file>
<file>images/paste.png</file>
<file>images/save.png</file>
</qresource>
</RCC>Each <file> element in the XML identifies a file in the application's source tree. The path is resolved relative to the directory containing the .qrc file.
[quote]
The path is also used by default to identify the file's content at runtime. That is, the file titlebarLeft.png will be available in the resource system as :/res/titlebarLeft.png or qrc:/res/titlebarLeft.png. To override this default run-time name, see Prefixes and Aliases.
[/quote]titlebarLeft.png is not in the file example, I know it's nitpicky but it does not instill confidence.
Further it is not made clear which instructions are being given for the QT creator IDE where one would assume that lots of setup is done for you, that is the point of an IDE as well as presumably for use of the library on it's own in whatever environment the programmer chooses.