Adds image resources to the target.
qul_add_resource(<target> FILES file1 [file2...] [PREFIX <path>] [BASE <path>] [OUTPUT_DIRECTORY <path>])
The listed files become resources that can be accessed from QML files via resource URIs. Currently only image resources are supported.
Resources can have CMake source file properties. These properties must be set before
qul_add_resource is called. For a list of properties, see the CMake Reference.
Internally, the resource descriptions are collected and passed to the qulrcc resource compiler as a JSON file.
qulrcc generates C++ files for them, as well as a JSON file that maps resource names to symbol names. The C++ files are compiled into the target and the output JSON file is used by qmltocpp to look up resource names and emit symbol references into generated code.
FILES argument takes a list of space-separated file paths, relative to the current source directory.
You can set the
OUTPUT_DIRECTORY option to control where the generated files are placed. If the path is relative, it is relative to the current build directory.
PREFIX path adds a prefix to the resource URI that the files are placed in. For example, if
PREFIX is "images" and one of the
FILES is "map/small.png", then the path in the resource filesystem will be "qrc:/images/map/small.png". The default prefix is "/".
BASE path determines the anchor for the computed resource URIs. For example, if
BASE is "data" and one of the
FILES is "data/images/foo.png", then the path resource filesystem will be "qrc:/images/foo.png". The default base is the current source directory.
Store image in compressed format.
Copy image data to RAM for fast access.
Enable optimizations for rotating the image at runtime.
Enable optimizations for scaling the image at runtime.
Note: These properties are set for individual resources using the
set_source_files_properties CMake function. To set a value that applies to all resources by default, use
QUL_DEFAULT_<property>. It's required to set source file properties before calling
# Store all images in compressed format by default, except for button.png set(QUL_DEFAULT_COMPRESSION ON) set_source_files_properties(button.png PROPERTIES QUL_COMPRESSION OFF) qul_add_resource(...)
# Used in QML as "qrc:/button.png" and "qrc:/nav/arrow.png", # or simply as "button.png" and "nav/arrow.png". qul_add_resource(example_app FILES button.png nav/arrow.png)
set_source_files_properties(big/button.png PROPERTIES QUL_COMPRESSION ON QUL_OPTIMIZE_FOR_SCALE ON) # The resource path becomes "qrc:/images/button.png" qul_add_resource(example_app FILES big/button.png BASE big PREFIX images)
This command was introduced in Qt Quick Ultralite 1.1.
See also Managing Resources and Assets.
Available under certain Qt licenses.
Find out more.