[英]QML cannot open an image more than once
In one of my QML pages, there are 1 back button and a listview containing an image and a text on each row. 在我的QML页面之一中,有1个后退按钮和一个列表视图,每行包含一个图像和一个文本。 I use a test image for both back button and listview row item.
我对返回按钮和listview行项目都使用了测试图像。 The back button can show the image but the listview complains about "QML Image: Cannot open: qrc:/../../../Users/Jerry/Desktop/LA.png".
后退按钮可以显示图像,但列表视图抱怨“ QML图像:无法打开:qrc:/../../../ Users / Jerry / Desktop / LA.png”。
Both the image and all QML files are under Resources. 图像和所有QML文件都在“资源”下。 Here is the code.
这是代码。
import QtQuick 2.0
import QtQuick.Controls 1.2
Rectangle {
anchors.fill: parent
Item {
id: advancedBackground
anchors.fill: parent
Button {
id: backButton
width: 25
height: 25
anchors.top: parent.top
anchors.topMargin: 25
anchors.left: parent.left
anchors.leftMargin: 25
opacity: backMouseArea.containsMouse ? 0.9 : 0.1
MouseArea {
id: backMouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
leftArrow.visible = true;
rightArrow.visible = false;
stackView.pop();
}
}
Image {
anchors.fill: parent
fillMode: Image.PreserveAspectFit
// image works fine here
source: "qrc:/../../../Users/Jerry/Desktop/LA.png"
}
}
ListView{
id: listView
anchors.rightMargin: 40
anchors.leftMargin: 40
anchors.bottomMargin: 30
anchors.topMargin: 90
anchors.fill: parent
delegate: Item {
x: 5
width: parent.height
height: 40
Image {
height: parent.height; width: parent.height
anchors.left: parent.left
fillMode: Image.PreserveAspectFit
source: imageSource
}
Text {
text: name
height: parent.height
width: parent.width
anchors.left: parent.left
anchors.leftMargin: 50
anchors.centerIn: parent
font.bold: true
anchors.horizontalCenter: parent.horizontalCenter
}
}
model: ListModel {
ListElement {
name: "test1"
// image doesn't work here
imageSource: "qrc:/../../../Users/Jerry/Desktop/LA.png"
}
ListElement {
name: "test2"
// image doesn't work here
imageSource: "qrc:/../../../Users/Jerry/Desktop/LA.png"
}
}
}
}
} }
Under the Resources, it includes AdvancedPages.qml and ../../../Users/Jerry/Desktop/LA.png 在“资源”下,它包括AdvancedPages.qml和../../../Users/Jerry/Desktop/LA.png
I think you should get rid of relative path to your image. 我认为您应该摆脱图像的相对路径。 The path should be like
qrc:/images/LA.png
. 路径应类似于
qrc:/images/LA.png
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.