qt_import_plugins

指定要導入 (或排除) 的自定義插件集。

命令的定義在 Core 組件對於 Qt6 包,可以像這樣加載:

find_package(Qt6 REQUIRED COMPONENTS Core)
					

該命令在 Qt 5.14 引入。

概要

qt_import_plugins(target
                  [INCLUDE plugin ...]
                  [EXCLUDE plugin ...]
                  [INCLUDE_BY_TYPE plugin_type plugin ...]
                  [EXCLUDE_BY_TYPE plugin_type]
                  [NO_DEFAULT]
)
					

無版本命令 被禁用,使用 qt6_import_plugins() 代替。它支持如此命令的一組相同自變量。

描述

Specifies a custom set of plugins to import. The optional arguments: INCLUDE , EXCLUDE , INCLUDE_BY_TYPE ,和 EXCLUDE_BY_TYPE , can be used more than once.

  • INCLUDE – can be used to specify a list of plugins to import.
  • EXCLUDE – can be used to specify a list of plugins to exclude.
  • INCLUDE_BY_TYPE – can be used to override the list of plugins to import for a certain plugin type.
  • EXCLUDE_BY_TYPE – can be used to specify a plugin type to exclude; then no plugins of that type are imported.
  • NO_DEFAULT – prevent the default plugins from being included automatically (for example, the default platform plugin).

Qt 提供插件類型,譬如 imageformats , platforms ,和 sqldrivers .

動態插件

If plugins are dynamic libraries, the function controls the plugin deployment. Using this function, you may exclude specific plugin types from being packaged into an Android APK, for example:

qt_add_executable(MyApp ...)
...
qt_import_plugins(MyApp EXCLUDE_BY_TYPE imageformats)
					

In the snippet above, all plugins that have the imageformats type will be excluded when deploying MyApp . The resulting Android APK will not contain any of the imageformats 插件。

If the command isn't used, the target automatically deploys all plugins that belong to the Qt modules that the target is linked against.

靜態插件

If the command isn't used the target automatically links against a sane set of default static plugins, for each Qt module that the target is linked against. For more information, see target_link_libraries .

Each plugin comes with a C++ stub file that automatically initializes the static plugin. Consequently, any target that links against a plugin has this C++ file added to its SOURCES .

範例

qt_add_executable(myapp main.cpp)
target_link_libraries(myapp Qt6::Gui Qt6::Sql)
qt_import_plugins(myapp
    INCLUDE Qt6::QCocoaIntegrationPlugin
    EXCLUDE Qt6::QMinimalIntegrationPlugin
    INCLUDE_BY_TYPE imageformats Qt6::QGifPlugin Qt6::QJpegPlugin
    EXCLUDE_BY_TYPE sqldrivers
)
					

In the snippet above, the following occurs with the executable myapp :

  • The Qt6::QCocoaIntegrationPlugin is imported into myapp.
  • The Qt6::QMinimalIntegrationPlugin plugin is excluded from being automatically imported into myapp.
  • The default list of plugins for imageformats is overridden to only include Qt6::QGifPlugin and Qt6::QJpegPlugin .
  • 所有 sqldrivers plugins are excluded from automatic importing.

另請參閱 qt_import_qml_plugins() .