|  | Home

# QtNPFactory Class Reference

The QtNPFactory class provides the factory for plugin objects. More...

     #include <QtNPFactory>

- List of all members, including inherited members

## Public Functions

| QtNPFactory ()
virtual | ~QtNPFactory ()
virtual QObject * | createObject ( const QString & type ) = 0
virtual QStringList | mimeTypes () const = 0
virtual QString | pluginDescription () const = 0
virtual QString | pluginName () const = 0

## Detailed Description

The QtNPFactory class provides the factory for plugin objects.

Implement this factory once in your plugin project to provide information about the plugin and to create the plugin objects. Subclass QtNPFactory and implement the pure virtual functions, and export the factory using the `QTNPFACTORY_EXPORT()` macro.

If you use the Q_CLASSINFO macro in your object classes you can use the `QTNPFACTORY_BEGIN()`, `QTNPCLASS()` and `QTNPFACTORY_END()` macros to generate a factory implementation:

     class Widget : public QWidget
     {
         Q_OBJECT
         Q_CLASSINFO("MIME", "application/x-graphable:g1n:Graphable data")
     public:
         ...
     };

     QTNPFACTORY_BEGIN("Plugin name", "Plugin description")
         QTNPCLASS(WidgetClass)
     QTNPFACTORY_END()

The classes exposed must provide a constructor.

If Qt is linked to the plugin as a dynamic library, only one instance of QApplication will exist across all plugins that have been made with Qt. So, your plugin should tread lightly on global settings. Do not, for example, use QApplication::setFont() - that will change the font in every widget of every Qt-based plugin currently loaded!

## Member Function Documentation

### QtNPFactory::QtNPFactory ()

Creates a QtNPFactory.

### QtNPFactory::~QtNPFactory () `[virtual]`

Destroys the QtNPFactory.

This is called by the plugin binding code just before the plugin is about to be unloaded from memory. If createObject() has been called, a QApplication will still exist at this time, but will be deleted shortly after, just before the plugin is deleted.

### QObject * QtNPFactory::createObject ( const QString & type ) `[pure virtual]`

Reimplement this function to return the QObject or QWidget subclass supporting the mime type type, or 0 if the factory doesn't support the type requested.

type will be in the same form as the leftmost (mime) part of the string(s) returned by mimeTypes(), e.g. "image/png".

### QStringList QtNPFactory::mimeTypes () const `[pure virtual]`

Reimplement this function to return the MIME types of the data formats supported by your plugin. The format of each string is mime:extension(s):description:

     QStringList mimeTypes() const
     {
         QStringList list;
         list << "image/x-png:png:PNG Image"
              << "image/png:png:PNG Image"
              << "image/jpeg:jpg,jpeg:JPEG Image";
         return list;
     }

### QString QtNPFactory::pluginDescription () const `[pure virtual]`

Reimplement this function to return the description of the plugin.

### QString QtNPFactory::pluginName () const `[pure virtual]`

Reimplement this function to return the name of the plugin.