Qt静态插件开发与使用 红太狼 2022-04-22 13:18 230阅读 0赞 转载自:[https://doc.qt.io/qt-5/plugins-howto.html\#static-plugins][https_doc.qt.io_qt-5_plugins-howto.html_static-plugins] ## Static Plugins ## The normal and most flexible way to include a plugin with an application is to compile it into a dynamic library that is shipped separately, and detected and loaded at runtime. Plugins can be linked statically into your application. If you build the static version of Qt, this is the only option for including Qt's predefined plugins. Using static plugins makes the deployment less error-prone, but has the disadvantage that no functionality from plugins can be added without a complete rebuild and redistribution of the application. To link plugins statically, you need to add the required plugins to your build using `QTPLUGIN`. In the `.pro` file for your application, you need the following entry: QTPLUGIN += qjpeg \ qgif \ qkrcodecs qmake automatically adds the plugins to QTPLUGIN that are typically needed by the Qt modules used (see [QT][]), while more specialized plugins need to be added manually. The default list of automatically added plugins can be overridden per type. For example, to link the minimal plugin instead of the default Qt platform adaptation plugin, use: QTPLUGIN.platforms = qminimal If you want neither the default, nor the minimal QPA plugin to be linked automatically, use: QTPLUGIN.platforms = - The defaults are tuned towards an optimal out-of-the-box experience, but may unnecessarily bloat the application. It is recommended to inspect the linker command line built by qmake and eliminate unnecessary plugins. ### Details of Linking Static Plugins ### To cause static plugins actually being linked and instantiated, [Q\_IMPORT\_PLUGIN][Q_IMPORT_PLUGIN]() macros are also needed in application code, but those are automatically generated by qmake and added to your application project. If you do not want all plugins added to QTPLUGIN to be automatically linked, remove `import_plugins` from the `CONFIG` variable: CONFIG -= import_plugins ### Creating Static Plugins ### It is also possible to create your own static plugins, by following these steps: 1. Add `CONFIG += static` to your plugin's `.pro` file. 2. Use the [Q\_IMPORT\_PLUGIN][Q_IMPORT_PLUGIN]() macro in your application. 3. Use the [Q\_INIT\_RESOURCE][Q_INIT_RESOURCE]() macro in your application if the plugin ships qrc files. 4. Link your application with your plugin library using `LIBS` in the `.pro` file. See the [Plug & Paint][Plug _ Paint] example and the associated [Basic Tools][] plugin for details on how to do this. **Note: **If you are not using qmake to build your plugin you need to make sure that the `QT_STATICPLUGIN` preprocessor macro is defined. ## Deploying and Debugging Plugins ## The [Deploying Plugins][] document covers the process of deploying plugins with applications and debugging them when problems arise. **See also **[QPluginLoader][], [QLibrary][], and [Plug & Paint Example][Plug _ Paint]. [https_doc.qt.io_qt-5_plugins-howto.html_static-plugins]: https://doc.qt.io/qt-5/plugins-howto.html#static-plugins [QT]: https://doc.qt.io/qt-5/qmake-variable-reference.html#qt [Q_IMPORT_PLUGIN]: https://doc.qt.io/qt-5/qtplugin.html#Q_IMPORT_PLUGIN [Q_INIT_RESOURCE]: https://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE [Plug _ Paint]: https://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-app-example.html [Basic Tools]: https://doc.qt.io/qt-5/qtwidgets-tools-plugandpaint-plugins-basictools-example.html [Deploying Plugins]: https://doc.qt.io/qt-5/deployment-plugins.html [QPluginLoader]: https://doc.qt.io/qt-5/qpluginloader.html [QLibrary]: https://doc.qt.io/qt-5/qlibrary.html
还没有评论,来说两句吧...