Cache Image in QML code
-
Hi. I am trying to reduce load on the network by caching some images from the Internet. I want to load images from cache at start, and after displaying load them from Internet and update if needed. I found that I can use QQuickImageProvider class for that by overloading requestImage function. But that way looks too complicated for me - as I understand Qt do not support synchronous requests, so I cannot stop function requestImage until file loaded. Is there any nice way to cache images between program starts?
-
I didn't do it, but if I would I'll do in the following way:
Into QML Image, I'll use the scheme for ImageProvider:
@
Image {
source: "image://Cached/image1.png"
}
@In the QQuickImageProvider:
if the image1.png is in the cache, it'll return it.
if the image1.png is not in the cache, it'll return an predefined image with "loading image".
in both case, I'll notify to an object for handling cache that image1.png has been requested.In a CacheHandler object:
for each notification of request, I'll do any network stuff for checking if the image1.png has to been downloaded for the first time or just need to be updated
after each new updating of cache items, I'll broadcast a signal for refreshing the Image QML elementsIn QML Image, I'll handle in someway the refreshing of the image connecting the signal of CacheHandler with a function for updating the image.