How to clear Image cache?
-
Image { id: img anchors.fill: parent smooth: true source: "file:///Volumes/D/x.png" fillMode: Image.PreserveAspectFit MouseArea { anchors.fill: parent onClicked: { if(img.cache) { img.cache = false; } else { img.cache = true; } } } }
How to clear Image cache?
-
Image { id: img anchors.fill: parent smooth: true source: "file:///Volumes/D/x.png" fillMode: Image.PreserveAspectFit MouseArea { anchors.fill: parent onClicked: { if(img.cache) { img.cache = false; } else { img.cache = true; } } } }
How to clear Image cache?
-
@senmx said in How to clear Image cache?:
How to clear Image cache?
I don't think that clearing image cache is what you want.
Can you please explain what you want to do and why you think you have to clear this cache?@KroMignon Thanks, for the time being, do not enable the cache to solve the problem. My needs: "After the picture is modified, the display must be updated."
-
@KroMignon Thanks, for the time being, do not enable the cache to solve the problem. My needs: "After the picture is modified, the display must be updated."
@senmx So you want that after the .png file is modified then you want the image to be updated. That cannot be done with QML. You have to use QFileSystemWatcher to monitor the file and then reload the image
If you want to reload the image when pressed then you can do the following:
onClicked: { img.source = "" img.source = "file:///Volumes/D/x.png" }
-
@KroMignon Thanks, for the time being, do not enable the cache to solve the problem. My needs: "After the picture is modified, the display must be updated."
@senmx said in How to clear Image cache?:
Thanks, for the time being, do not enable the cache to solve the problem. My needs: "After the picture is modified, the display must be updated."
To force Image reload, you have to change
Image.source
property.
So the easiest way is to follow @eyllanesc code example ;)Please, always try to give the main problem you try to solve. Sometimes, when trying to solve a problem, you are on the wrong way. If you ask for the main issue, you will get the right answer to solve it :)
-
@senmx So you want that after the .png file is modified then you want the image to be updated. That cannot be done with QML. You have to use QFileSystemWatcher to monitor the file and then reload the image
If you want to reload the image when pressed then you can do the following:
onClicked: { img.source = "" img.source = "file:///Volumes/D/x.png" }
@eyllanesc @KroMignon Thks.
onClicked: { img.cache = false; img.source = "" img.source = "file:///Volumes/D/x.png" }
In this way, the update must first set "cache=false" to work. But if set "cahce=true" after the update, the image will return to the old one.