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

Note: On Infineon TRAVEO T2G and RH850 D1M1A due to the lack of touch input, the example will automatically switch between images every reloadInSeconds seconds.

Project structure

The image cache is enabled in the QmlProject file.

CMake project file

To enable image caching:

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

...
        MCU.Config {
                maxResourceCacheSize: 2211840
        }
...
        ImageFiles {
                files: [
                "images/basse-terre-guadeloupe.jpg",
                "images/grand-canyon-arizona.jpg",
                "images/grand-canyon-national-park.jpg",
                "images/Jokulsarlon-glacier-lagoon-iceland.jpg",
                "images/reine-lofoten-islands.jpg",
                "images/sequoia-national-park.jpg",
                "images/sogn-og-fjordane.jpg",
                "images/yosemite-national-park.jpg",
                ]
                MCU.resourceCachePolicy: "OnDemand"
        }
...

If your target OS is FreeRTOS, set the heap size

...
        qul_override_freertos_heap_size(image_cache "8 * 1024 * 1024 + ${cache_size_in_bytes}")
...

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

Files:

Images:

See also ImageFiles.MCU.resourceCachePolicy and Image Caching.

Available under certain Qt licenses.
Find out more.