简体   繁体   English

QML不能多次打开图像

[英]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.

相关问题 PHPMailer addStringEmbeddedImage并多次添加同一图像 - PHPMailer addStringEmbeddedImage and adding the same image more than once Base64嵌入式图像使用多次 - Base64 Inline Image use more than once 使用不止一次时图像质量下降 - image quality deteriorates when used more than once 开放图谱协议:为什么要包含多个图像? - Open Graph Protocol: Reasons to include more than one image anyone? 无法上传尺寸超过2mb +的图像 - Cannot upload image with size more than 2mb+ Onload方法在连续重新加载到应用程序中时多次调用自身(var image = new Image(),javascript问题) - Onload method is calling itself more than once on successive reloads to application (var image = new Image(), javascript issue) 我想多次使用同一张图片,并且我希望Web浏览器仅下载一次该图片,该怎么做? - I want to use the same image more than once and I would like the web browser to download this image only once, how to do it? 如何在 html 和 javascript 上使用 onclick 多次更改图像源 - how to change an image source more than once using onclick on html and javascript Android:停止同时使用多个随机图片 - Android: Stopping random image being used more than once at the same time 如何正确打开/解码具有超过65500 * 65500像素的jpeg图像? - How can I correctly open/decode a jpeg image that has more than 65500 * 65500 pixels?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM