Qt6 topics merged with General

how to change source of the image item dynamically

  • 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 .

  • @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.

  • 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
            cache: false
            anchors.centerIn: parent
            anchors.fill: parent
            onClicked: {
                img.source = ""
                img.source = src

  • thanks @LeLev it worked

Log in to reply