< 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 .