Importierte Ziele
Jedes Qt-Modul, das geladen wird, definiert ein CMake-Bibliotheksziel. Die Zielnamen beginnen mit Qt6::
, gefolgt vom Modulnamen. Zum Beispiel: Qt6::Core
, Qt6::Gui
. Übergeben Sie den Namen des Bibliotheksziels an target_link_libraries
, um die entsprechende Bibliothek zu verwenden.
Hinweis: Die Targets sind auch mit dem Präfix Qt::
verfügbar: Qt::Core
, Qt::Gui
, und so weiter. Siehe auch Qt 5 und Qt 6 Kompatibilität.
Importierte Targets werden mit den gleichen Konfigurationen wie bei der Konfiguration von Qt erstellt. Das heißt:
- Wenn Qt mit dem Schalter
-debug
konfiguriert wurde, wird ein importiertes Ziel mit der DEBUG-Konfiguration erstellt. - Wenn Qt mit dem Schalter
-release
konfiguriert wurde, wird ein importiertes Ziel mit der RELEASE-Konfiguration erstellt. - Wenn Qt mit dem Schalter
-debug-and-release
konfiguriert wurde, werden importierte Ziele sowohl mit der RELEASE- als auch der DEBUG-Konfiguration erstellt.
Wenn Ihr Projekt über benutzerdefinierte CMake
Build-Konfigurationen verfügt, müssen Sie Ihre benutzerdefinierte Konfiguration entweder der Debug- oder der Release-Konfiguration von Qt zuordnen.
find_package(Qt6 REQUIRED COMPONENTS Core) set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage") # set up a mapping so that the Release configuration for the Qt imported target is # used in the COVERAGE CMake configuration. set_target_properties(Qt6::Core PROPERTIES MAP_IMPORTED_CONFIG_COVERAGE "RELEASE")
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.