Imported targets
导入目标
Each Qt module that is loaded defines a CMake library target. The target names start with Qt6::, followed by the module name. For example: Qt6::Core, Qt6::Gui. Pass the name of the library target to target_link_libraries to use the respective library.
加载的每个Qt模块定义一个CMake库目标。目标名称以Qt6::开头,后跟模块名称。例如:Qt6::Core、Qt6::Gui。将库目标的名称传递给target_link_libraries以使用相应的库。
Note: The targets are also available with a
Qt::prefix:Qt::Core,Qt::Gui, and so on. See also Qt 5 and Qt 6 compatibility.注意:目标也可以使用Qt::prefix:Qt::Core、Qt::Gui等。另请参见Qt 5和Qt 6兼容性。
Imported targets are created with the same configurations as when Qt was configured. That is:
导入的目标使用与配置Qt时相同的配置创建。也就是说:
- If Qt was configured with the
-debugswitch, an imported target with the DEBUG configuration is created. - 如果Qt配置了-debug开关,则会创建带有调试配置的导入目标。
- If Qt was configured with the
-releaseswitch, an imported target with the RELEASE configuration is created. - 如果Qt配置了-release开关,则会创建具有release配置的导入目标。
- If Qt was configured with the
-debug-and-releaseswitch, then imported targets are created with both RELEASE and DEBUG configurations. - 如果Qt配置了
-debug-and-release开关,那么将使用release和debug配置创建导入的目标。
If your project has custom CMake build configurations, you have to map your custom configuration to either the debug or the release Qt configuration.
如果您的项目有定制的CMake构建配置,则必须将定制配置映射到debug配置或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")
这篇博客介绍了如何在CMake中使用Qt6模块。每个加载的Qt模块都会定义一个对应的库目标,如Qt6::Core、Qt6::Gui,这些目标可以根据配置(如debug或release)进行链接。通过设置target_link_libraries,可以将库目标应用到项目中。此外,还提到了Qt5和Qt6的兼容性,并指出了在自定义CMake配置下如何映射Qt导入目标的配置。
2455

被折叠的 条评论
为什么被折叠?



