Extending Qt Creator Manual | The Plugin Manager, the Object Pool, and Registered Objects

Extending Qt Creator Manual 4.3.0

# The Plugin Manager, the Object Pool, and Registered Objects

Usually, plugins do not need to access the plugin manager directly. They interact with it mostly indirectly through the ExtensionSystem::IPlugin interface. There are occasions though, where using the plugin manager API is necessary. Plugins need to access the plugin manager's object pool to extend some aspects of Qt Creator, for example to add pages to the options dialog. They can also utilize the object pool to provide extension points for other plugins (see Extending and Providing Interfaces).

## Plugin Manager

The plugin manager handles all the details regarding finding plugins, reading their description files, resolving plugin dependencies, loading and initializing all plugins in the right order, and passing on command line arguments.

In addition, the plugin manager manages an object pool, where objects can be registered and retrieved depending on different criteria.

Most interaction of plugins with the plugin manager should be done through the ExtensionSystem::IPlugin interface, but the following tables summarize some functions and signals that can be useful for plugins. See the ExtensionSystem::PluginManager reference documentation for the complete list.

Function | Description
--- | ---
instance() | Returns the singleton plugin manager instance, for example for connecting to signals.
addObject() | Registers an object in the object pool. Also available through ExtensionSystem::IPlugin::addObject().
removeObject() | Unregisters an object from the object pool. Also available through ExtensionSystem::IPlugin::removeObject().
getObjects<T>() | Returns all objects of type T that are registered in the object pool. This respects Aggregations.
getObject<T>() | Returns one object of type T that is registered in the object pool. This respects Aggregations.
getObjectByName(const QString &name) | Returns one object with the given object name that is registered in the object pool.
getObjectByClassName(const QString &className) | Returns one object with the given class name that is registered in the object pool.

Signal | Description
--- | ---
objectAdded(QObject *object) | Sent after an object is registered in the object pool.
aboutToRemoveObject(QObject *object) | Sent just before an object is unregistered from the object pool.
initializationDone() | Sent when plugins are running and all delayed initialization is done.

## Object Pool and Registered Objects

Plugins can register objects to a common pool that is managed by the plugin manager. Objects in the pool must derive from QObject, there are no other prerequisites.

All objects of a specified type can be retrieved from the object pool via the getObjects() and getObject() functions. They are aware of Aggregation::Aggregate, so these functions use the Aggregation::query() functions instead of qobject_cast to determine the matching objects.

It is also possible to retrieve an object with a specific object name with getObjectByName() (see QObject::objectName()), and an object with a given class name with getObjectByClassName() (see QMetaObject::className()).

Whenever the state of the object pool changes, a corresponding objectAdded() or aboutToRemoveObject() signal is emitted by the plugin manager.

A common use case for the object pool is that a plugin (or the application) provides an extension point for other plugins, which is a class that can be implemented and added to the object pool to be retrieved by the providing plugin. It is also possible to use the object pool to provide access to an object without actually linking against the providing plugin library. See Extending and Providing Interfaces for details.