Objetivos importados

Cada módulo de Qt que se carga define un objetivo de biblioteca de CMake. Los nombres de los objetivos comienzan por Qt6::, seguidos del nombre del módulo. Por ejemplo: Qt6::Core, Qt6::Gui. Pasa el nombre del objetivo de biblioteca a target_link_libraries para utilizar la biblioteca correspondiente.

Nota: Los objetivos también están disponibles con el prefijo « Qt:: »: « Qt::Core », « Qt::Gui », etc. Véase también Compatibilidad entre Qt 5 y Qt 6.

Los objetivos importados se crean con las mismas configuraciones que cuando se configuró Qt. Es decir:

  • Si Qt se configuró con el parámetro -debug, se crea un objetivo importado con la configuración DEBUG.
  • Si Qt se configuró con el modificador « -release », se crea un objetivo importado con la configuración RELEASE.
  • Si Qt se configuró con el modificador « -debug-and-release », los objetivos importados se crean con las configuraciones RELEASE y DEBUG.

Si tu proyecto tiene configuraciones de compilación personalizadas de « CMake », debes asignar tu configuración personalizada a la configuración de Qt de depuración o de lanzamiento.

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.