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

Set the QUL_TEXTURE_CACHE and QUL_DEFAULT_COPY_TO_RAM CMake variables. Ensure tbat these variables are set before the calls to qul_add_target and qul_add_resource.

Note: QUL_DEFAULT_COPY_TO_RAM makes all resources cachable by default. If that's not desired, see QUL_COPY_TO_RAM.

...
set(QUL_TEXTURE_CACHE ${cache_size_in_bytes})
set(QUL_DEFAULT_COPY_TO_RAM "OnDemand")
...
qul_add_target(image_cache ImageModel.cpp)
...

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_COMPRESSION and Image Caching.

Available under certain Qt licenses.
Find out more.