C

Qt Quick Ultralite image_cache Example

Demonstrates how to use image cache in Qt Quick Ultralite.

Overview

The example shows two sets of images. The current set is changed every reloadInSeconds seconds and the cache size is set to fit 4 images at a time, which is the amount of images in each image set. Thus, the cache can hold all images from the currently active image set. Images are loaded into the cache when they are requested to be rendered on the display - when a new image is accessed by swiping. When the cache is full, it removes the oldest image to free the space for the currently requested image.

Target platforms

Project structure

The image cache is enabled in the CMake project file.

CMake project file

To enable image caching:

Setting the asset cache policy on individual resources is possible by using the QUL_RESOURCE_CACHE_POLICY CMake variable. This can be useful when only certain images in the application should be eligible to be cached.

Note: Ensure that QUL_RESOURCE_CACHE_POLICY variable is set before the qul_add_target and qul_add_resource calls.

...
set(QUL_DEFAULT_RESOURCE_CACHE_POLICY "OnDemand")
...
app_target_default_entrypoint(image_cache image_cache)
qul_set_maximum_resource_cache_size(image_cache CACHE_SIZE ${cache_size_in_bytes})
...

If your target OS is FreeRTOS, set the heap size

...
    add_compile_definitions(configTOTAL_HEAP_SIZE=${heap_size})
...

Now, whenever the image is about to get drawn, the renderer checks the cache first.

Files:

Images:

See also QUL_RESOURCE_COMPRESSION and Image Caching.

Available under certain Qt licenses.
Find out more.