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
is called. For a list of properties, see the
Internally, the resource descriptions are collected and passed to the
resource compiler as a JSON file.
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
to look up resource names and emit symbol references into generated code.
argument takes a list of space-separated file paths, relative to the current source directory.
option to control where the generated files are placed. If the path is relative, it is relative to the current build directory.
path adds a prefix to the resource URI that the files are placed in. For example, if
is "images" and one of the
is "map/small.png", then the path in the resource filesystem will be "qrc:/images/map/small.png". The default prefix is "/".
path determines the anchor for the computed resource URIs. For example, if
is "data" and one of the
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.
Set the preferred color depth for the image.
Enable optimizations for rotating the image at runtime.
Enable optimizations for scaling the image at runtime.
These properties are set for individual resources using the
CMake function. To set a value that applies to all resources by default, use
. 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.
另请参阅 管理资源和资产 .