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. Cache Image in QML code
Forum Updated to NodeBB v4.3 + New Features

Cache Image in QML code

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    rus_phantom
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • GianlucaG Offline
      GianlucaG Offline
      Gianluca
      wrote on last edited by
      #2

      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 elements

      In QML Image, I'll handle in someway the refreshing of the image connecting the signal of CacheHandler with a function for updating the image.

      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