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
- MCIMX93-EVK
- MIMXRT1050
- MIMXRT1060
- MIMXRT1064
- MIMXRT1170
- STM32F769i
- STM32H750b
- RH850 D1M1A
- Infineon TRAVEO™ T2G
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:
- Set the resource cache size using MCU.Config.maxResourceCacheSize to desired size.
- Set the ImageFiles.MCU.resourceCachePolicy QmlProject property. It sets the asset cache policy to
OnDemand
for all the resources.
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:
- image_cache/CMakeLists.txt
- image_cache/ImageModel.cpp
- image_cache/ImageModel.h
- image_cache/image_cache.qml
- image_cache/mcu_image_cache.qmlproject
- image_cache/mcu_image_cache_RH850.qmlproject
- image_cache/mcu_image_cache_ek-ra6m3g.qmlproject
- image_cache/mcu_image_cache_rgb565.qmlproject
Images:
- image_cache/images/Jokulsarlon-glacier-lagoon-iceland.jpg
- image_cache/images/basse-terre-guadeloupe.jpg
- image_cache/images/grand-canyon-arizona.jpg
- image_cache/images/grand-canyon-national-park.jpg
- image_cache/images/reine-lofoten-islands.jpg
- image_cache/images/sequoia-national-park.jpg
- image_cache/images/sogn-og-fjordane.jpg
- image_cache/images/yosemite-national-park.jpg
See also ImageFiles.MCU.resourceCachePolicy and Image Caching.
Available under certain Qt licenses.
Find out more.