Home · All Classes · Grouped Classes · Annotated · Functions

QPluginManager Class Reference

The QPluginManager class simplifies plug-in loading and allows plugins to be enabled/disabled. More...

    #include <QPluginManager>

Inherits QObject.

Public Functions

Static Public Members

Additional Inherited Members


Detailed Description

The QPluginManager class simplifies plug-in loading and allows plugins to be enabled/disabled.

The most common use is to iterate over the list of plugins and load each one as follows:

    QPluginManager pluginManager( "Effects" );
    QStringList list = pluginManager.list();
    QStringList::Iterator it;
    QList<EffectsInterface*> effectList;
    for ( it = list.begin(); it != list.end(); ++it ) {
        QObject *instance = pluginManager->instance(*it);
        EffectsInterface *iface = 0;
        iface = qobject_cast<EffectsInterface*>(instance);
        if (iface) {
            effectList.append( iface );
        }
    }

The list() function returns a list of plugins, using the filenames of the plugins in the plugin directory. This does not require any plugins to be loaded, so it is very lightweight.

In order to load a plugin, call the instance() function with the name of the plugin to load. qobject_cast() may then be used to query for the desired interface.

If the application loading a plugin crashes during while loading the plugin, the plugin will be disabled. This prevents a plugin from permanently rendering an application unusable. Disabled plugins can be queried using disabledList() and reenabled using setEnabled().


Member Function Documentation

QPluginManager::QPluginManager ( const QString & type, QObject * parent = 0 )

Creates a QPluginManager for plugins of type with the given parent.

The plugins must be installed in the [qt_prefix]/plugins/type directory.

QPluginManager::~QPluginManager ()

Destroys the QPluginManager and releases any resources allocated by the PluginManager.

void QPluginManager::clear ()

Releases all resources allocated by the QPluginManager

const QStringList & QPluginManager::disabledList () const

Returns the list of plugins that have been disabled.

bool QPluginManager::inSafeMode ()   [static]

Returns true if Qtopia is currently in Safe Mode. In safe mode list() will return an empty list and no plugins should be loaded. This is to allow misbehaving plugins to be disabled.

QObject * QPluginManager::instance ( const QString & name )

Load the plug-in specified by name.

Returns the plugin interface if found, otherwise 0.

    QObject *instance = pluginManager->instance("name");
    if (instance) {
        EffectsInterface *iface = 0;
        iface = qobject_cast<EffectsInterface*>(instance);
        if (iface) {
            // We have an instance of the desired type.
        }
    }

If an instance is no longer required and resources need to be released, simply delete the returned instance.

bool QPluginManager::isEnabled ( const QString & name ) const

Returns true if the plug-in name is enabled.

const QStringList & QPluginManager::list () const

Returns the list of plugins that are available.

The plugin list is derived from the filenames of the plugins and does not force any plugins to be loaded.

void QPluginManager::setEnabled ( const QString & name, bool enabled = true )

Enables or disables plug-in name depending on the value of enabled. A disabled plug-in can still be loaded, but it will not be returned by list().

See also isEnabled().


Copyright © 2008 Nokia Trademarks
Qtopia 4.3.3