Obiettivi importati

Ogni modulo Qt caricato definisce un target di libreria CMake. I nomi dei target iniziano con Qt6::, seguito dal nome del modulo. Ad esempio: Qt6::Core, Qt6::Gui. Passare il nome del target di libreria a target_link_libraries per utilizzare la rispettiva libreria.

Nota: i target sono disponibili anche con il prefisso Qt::: Qt::Core, Qt::Gui e così via. Vedi anche Compatibilità con Qt 5 e Qt 6.

I target importati vengono creati con le stesse configurazioni utilizzate durante la configurazione di Qt. Ovvero:

  • Se Qt è stato configurato con l’opzione -debug, viene creato un target importato con la configurazione DEBUG.
  • Se Qt è stato configurato con l'opzione ` -release `, viene creato un target importato con la configurazione `RELEASE`.
  • Se Qt è stato configurato con l’opzione -debug-and-release, i target importati vengono creati con entrambe le configurazioni RELEASE e DEBUG.

Se il progetto presenta configurazioni di compilazione " CMake " personalizzate, è necessario mappare la configurazione personalizzata alla configurazione Qt "debug" o "release".

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.