Objetivos importados
Cada módulo Qt que se carga define un objetivo de biblioteca CMake. Los nombres de objetivo empiezan por Qt6::, seguido del nombre del módulo. Por ejemplo: Qt6::Core Qt6::Gui . Pase el nombre del objetivo de biblioteca a target_link_libraries para utilizar la biblioteca correspondiente.
Nota: Los objetivos también están disponibles con un prefijo Qt::: Qt::Core, Qt::Gui, etc. Véase también la compatibilidad con Qt 5 y Qt 6.
Los targets importados se crean con las mismas configuraciones que cuando se configuró Qt. Es decir:
- Si Qt se configuró con el modificador
-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, se crean objetivos importados con las configuraciones RELEASE y DEBUG.
Si su proyecto tiene configuraciones de compilación CMake personalizadas, tiene que asignar su configuración personalizada a la configuración 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.