qt - QML cannot open an image more than once -
in 1 of qml pages, there 1 button , listview containing image , text on each row. use test image both button , listview row item. button can show image listview complains "qml image: cannot open: qrc:/../../../users/jerry/desktop/la.png".
both image , qml files under resources. here 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 resources, includes advancedpages.qml , ../../../users/jerry/desktop/la.png
i think should rid of relative path image. path should qrc:/images/la.png.
Comments
Post a Comment