how to change source of the image item dynamically
-
wrote on 17 Dec 2019, 08:32 last edited by
i'm trying to display an image which will be updated with the same name i.e., different images will be saved with same name consider(Image.png),now how to update the image when image changes I tried using signal and slots to update the source of the image but it didn't worked ,can someone help me .
-
i'm trying to display an image which will be updated with the same name i.e., different images will be saved with same name consider(Image.png),now how to update the image when image changes I tried using signal and slots to update the source of the image but it didn't worked ,can someone help me .
wrote on 17 Dec 2019, 09:19 last edited by JonB@vamsi1992
Unless anyone else knows better for QML* (I don't use), assuming the file in question is a local file (i.e. not on the web) you will have to use https://doc.qt.io/qt-5/qfilesystemwatcher.html and its signals to recognise when the file has been changed, and then somehow refresh (however you do that in QML)..* EDIT Looks like @LeLev does know better than I for QML! Follow his advice below.
-
wrote on 17 Dec 2019, 09:32 last edited by
hi,
simply set cache property of the Image to false
Window { id: window visible: true width: 1280 height: 720 property string src: "file:///C:/Pictures/camL.png" Component.onCompleted: img.source = src Image{ id:img cache: false anchors.centerIn: parent } MouseArea{ anchors.fill: parent onClicked: { console.log("reloading") img.source = "" img.source = src } } }
-
wrote on 18 Dec 2019, 05:03 last edited by
thanks @LeLev it worked
1/4