summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2021-05-12 11:59:30 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2021-05-16 17:05:32 +0200
commit97228214bd63f37563669049bfa13d33efa97c48 (patch)
tree2426d0bd6ef796bbcbaad77f50d76a6f16209d70 /src/corelib/doc
parent282b724808ea4524ed09b9f0183055fdffc3c38a (diff)
Doc: Add CMake to the "Resource System" documentation
Pick-to: 6.1 Change-Id: I4c6a7cfb2f6351e9587d47ab6708d92a1a4e42a4 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/corelib/doc')
-rw-r--r--src/corelib/doc/snippets/resource-system/CMakeLists.txt23
-rw-r--r--src/corelib/doc/src/resource-system.qdoc24
2 files changed, 43 insertions, 4 deletions
diff --git a/src/corelib/doc/snippets/resource-system/CMakeLists.txt b/src/corelib/doc/snippets/resource-system/CMakeLists.txt
new file mode 100644
index 0000000000..29727bd958
--- /dev/null
+++ b/src/corelib/doc/snippets/resource-system/CMakeLists.txt
@@ -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]
diff --git a/src/corelib/doc/src/resource-system.qdoc b/src/corelib/doc/src/resource-system.qdoc
index 6e0b2fd1ae..e8ca4f5828 100644
--- a/src/corelib/doc/src/resource-system.qdoc
+++ b/src/corelib/doc/src/resource-system.qdoc
@@ -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