< QtPlugin > header files defines macros for defining plugins. 更多...
| Q_DECLARE_INTERFACE ( ClassName , Identifier ) | |
| Q_EXPORT_PLUGIN2 ( PluginName , ClassName ) | |
| Q_IMPORT_PLUGIN ( PluginName ) |
另请参阅 如何创建 Qt 插件 .
此宏关联给定 Identifier (字符串文字) 到接口类称为 ClassName 。 Identifier 必须唯一。例如:
Q_DECLARE_INTERFACE(BrushInterface, "com.trolltech.PlugAndPaint.BrushInterface/1.0")
通常,正确使用此宏是在类定义后对于 ClassName ,在 Header (头) 文件中。见 插件和描绘 范例了解细节。
若想要使用 Q_DECLARE_INTERFACE 采用在名称空间中声明的接口类,必须确保 Q_DECLARE_INTERFACE 不在名称空间中。例如:
namespace Foo { struct MyInterface { ... }; } Q_DECLARE_INTERFACE(Foo::MyInterface, "org.examples.MyInterface")
另请参阅 Q_INTERFACES (), Q_EXPORT_PLUGIN2 (),和 如何创建 Qt 插件 .
This macro exports the plugin class ClassName for the plugin specified by PluginName . The value of PluginName should correspond to the TARGET specified in the plugin's project file.
There should be exactly one occurrence of this macro in the source code for a Qt plugin, and it should be used where the implementation is written rather than in a header file.
范例:
Q_EXPORT_PLUGIN2(pnp_extrafilters, ExtraFiltersPlugin)
见 插件和描绘 范例了解细节。
该函数在 Qt 4.1 引入。
另请参阅 Q_DECLARE_INTERFACE () 和 如何创建 Qt 插件 .
此宏导入插件命名 PluginName , corresponding to the TARGET specified in the plugin's project file.
将此宏插入应用程序源代码,将允许您使用静态插件。
范例:
Q_IMPORT_PLUGIN(qjpeg)
静态插件还必须由链接器包括,当构建应用程序时。对于 Qt 预定义插件,可以使用
QTPLUGIN
将所需插件添加到您的构建中。例如:
TEMPLATE = app QTPLUGIN += qjpeg qgif qmng # image formats
另请参阅 静态插件 , 如何创建 Qt 插件 ,和 使用 qmake .