Doc: Add CMake to the "Resource System" documentation
Change-Id: I4c6a7cfb2f6351e9587d47ab6708d92a1a4e42a4 Reviewed-by: Paul Wicking <paul.wicking@qt.io> (cherry picked from commit 97228214bd63f37563669049bfa13d33efa97c48) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
eca1e5d385
commit
ef02470d81
23
src/corelib/doc/snippets/resource-system/CMakeLists.txt
Normal file
23
src/corelib/doc/snippets/resource-system/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
project(my_app)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Widgets)
|
||||
|
||||
#! [AUTORCC]
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
qt_add_executable(my_app
|
||||
application.qrc
|
||||
mainwindow.cpp)
|
||||
#! [AUTORCC]
|
||||
|
||||
#! [qt_add_resources]
|
||||
qt_add_resources(my_app "app_images"
|
||||
PREFIX "/"
|
||||
FILES
|
||||
"images/copy.png"
|
||||
"images/cut.png"
|
||||
"images/new.png"
|
||||
"images/open.png"
|
||||
"images/paste.png"
|
||||
"images/save.png")
|
||||
#! [qt_add_resources]
|
@ -38,7 +38,7 @@
|
||||
(icons, translation files, etc.) and you don't want to run the
|
||||
risk of losing the files.
|
||||
|
||||
The resource system is based on tight cooperation between \l qmake,
|
||||
The resource system is based on tight cooperation between the build system,
|
||||
\l rcc (Qt's resource compiler), and QFile.
|
||||
|
||||
\section1 Resource Collection Files (\c{.qrc})
|
||||
@ -122,9 +122,25 @@
|
||||
|
||||
\section2 Compiled-In Resources
|
||||
|
||||
For a resource to be compiled into the binary the \c .qrc file must be
|
||||
mentioned in the application's \c .pro file so that \c qmake knows
|
||||
about it. For example:
|
||||
For a resource to be compiled into the binary, the \c .qrc file must be
|
||||
mentioned in the application's project file so that the build tool knows
|
||||
about it.
|
||||
|
||||
In CMake projects, one can use CMake's built-in \c AUTORCC feature to add \c
|
||||
.qrc files directly as source files:
|
||||
|
||||
\snippet resource-system/CMakeLists.txt AUTORCC
|
||||
|
||||
See \l {https://cmake.org/cmake/help/latest/prop_tgt/AUTORCC.html}
|
||||
{CMake's AUTORCC documentation}.
|
||||
|
||||
Qt's own CMake function \l qt_add_resources allows more control over the
|
||||
creation of resources. For example, it allows to specify the content of the
|
||||
resource directly in the project file without writing a \c .qrc file first:
|
||||
|
||||
\snippet resource-system/CMakeLists.txt qt_add_resources
|
||||
|
||||
In qmake projects, assign the \c .qrc files to the \l RESOURCES variable:
|
||||
|
||||
\snippet resource-system/application.pro 0
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user