Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to change source of the image item dynamically
Forum Update on Monday, May 27th 2025

how to change source of the image item dynamically

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vamsi1992
    wrote on last edited by
    #1

    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 .

    JonBJ 1 Reply Last reply
    0
    • V vamsi1992

      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 .

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

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

      1 Reply Last reply
      1
      • ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        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
                }
            }
        }
        
        1 Reply Last reply
        3
        • V Offline
          V Offline
          vamsi1992
          wrote on last edited by
          #4

          thanks @LeLev it worked

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved