Importierte Ziele

Jedes geladene Qt-Modul definiert ein CMake-Bibliotheksziel. Die Zielnamen beginnen mit „ Qt6:: “, gefolgt vom Modulnamen. Beispiele: „ Qt6::Core “, „ Qt6::Gui “. Übergeben Sie den Namen des Bibliotheksziels an „ target_link_libraries “, um die jeweilige Bibliothek zu verwenden.

Hinweis: Die Ziele sind auch mit dem Präfix „ Qt:: “ verfügbar: „ Qt::Core “, „ Qt::Gui “ usw. Siehe auch Kompatibilität mit Qt 5 und Qt 6.

Importierte Ziele werden mit denselben Konfigurationen erstellt wie bei der Konfiguration von Qt. Das heißt:

  • Wenn Qt mit dem Schalter „ -debug “ konfiguriert wurde, wird ein importiertes Ziel mit der Konfiguration „DEBUG“ erstellt.
  • Wurde Qt mit dem Schalter „ -release “ konfiguriert, wird ein importiertes Ziel mit der Konfiguration „RELEASE“ erstellt.
  • Wurde Qt mit dem Schalter „ -debug-and-release “ konfiguriert, werden importierte Ziele sowohl mit der RELEASE- als auch mit der DEBUG-Konfiguration erstellt.

Wenn Ihr Projekt benutzerdefinierte „ CMake “-Build-Konfigurationen enthält, 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")

© 2026 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.