I can load an image stored in qrc resource at start up just fine but when I try to load the very same image (for demo purposes only), I get a 'QML Image: Cannot open: qrc:../....' error.
Clicking on the image repeatedly will even give the same error to the same PNG file that was loaded at startup (with no error). It's as if the paths change once the program is up and running.
Essentially, neither 'gray_button1.png' nor 'gray_button2.png' can be opened for reasons unknown once the program is running...
One other fact:the QML file running this script itself is stored/located in the QML.qrc file.
import QtQuick 2.7
Rectangle {
id: baseBtn
color: "transparent"
property string activeSource:"qrc:../Root/Images/gray_button1.png";
property string inactiveSource:"qrc:../Root/Images/gray_button2.png";
property string previousText:""
property bool active:false
onActiveChanged:{
if (active)
btnImage.source = activeSource;
else
btnImage.source = inactiveSource;
}
MouseArea{
id: mouseArea1
anchors.fill:parent
onClicked: {
active = !active;
}
Image {
id: btnImage
width:parent.width
height: parent.height
anchors.horizontalCenter: parent.horizontalCenter
source:"qrc:../Root/Images/gray_button2.png"; //opens and loads fine at start up -> appears normal
z:0
}
}
}
Here is the file structure
Application
-->Root
---->Images
gray_button1.png
gray_button2.png
-->QML
qml.qrc
button.qml
...{*.qml}
:/prefix/file. What does..mean in your case? Please provide the folder structure. - folibis