|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# <QtPlugin> - Macros for Defining Plugins

The <QtPlugin> header files defines macros for defining plugins. More...

### Macros

- Q_DECLARE_INTERFACE ( ClassName, Identifier )
- Q_EXPORT_PLUGIN2 ( PluginName, ClassName )
- Q_IMPORT_PLUGIN ( PluginName )

## Detailed Description

The <QtPlugin> header files defines macros for defining plugins.

See also How to Create Qt Plugins.

## Macro Documentation

### Q_DECLARE_INTERFACE ( ClassName, Identifier )

This macro associates the given Identifier (a string literal) to the interface class called ClassName. The Identifier must be unique. For example:

        Q_DECLARE_INTERFACE(BrushInterface,
                            "com.trolltech.PlugAndPaint.BrushInterface/1.0")

This macro is normally used right after the class definition for ClassName, in a header file. See the Plug & Paint example for details.

If you want to use Q_DECLARE_INTERFACE with interface classes declared in a namespace then you have to make sure the Q_DECLARE_INTERFACE is not inside a namespace though. For example:

        namespace Foo
        {
            struct MyInterface { ... };
        }

        Q_DECLARE_INTERFACE(Foo::MyInterface, "org.examples.MyInterface")

See also Q_INTERFACES(), Q_EXPORT_PLUGIN2(), and How to Create Qt Plugins.

### Q_EXPORT_PLUGIN2 ( PluginName, ClassName )

This macro exports the plugin class ClassName with the name PluginName. There should be exactly one occurrence of this macro in a Qt plugin's source code (in an implementation file).

Example:

        Q_EXPORT_PLUGIN2(pnp_extrafilters, ExtraFiltersPlugin)

See the Plug & Paint example for details.

This function was introduced in Qt 4.1.

See also Q_DECLARE_INTERFACE() and How to Create Qt Plugins.

### Q_IMPORT_PLUGIN ( PluginName )

This macro imports the plugin named PluginName. Inserting this macro into your application's source code will allow you to make use of a static plugin.

Example:

        Q_IMPORT_PLUGIN(qjpeg)

Static plugins must also be included by the linker when your application is built. For Qt's predefined plugins, you can use the `QTPLUGIN` to add the required plugins to your build. For example:

        TEMPLATE      = app
        QTPLUGIN     += qjpeg qgif qmng    # image formats

See also Static Plugins, How to Create Qt Plugins, and Using qmake.