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.

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.

FunctionDescription
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().
allObjects()Returns an unfiltered list of all objects that are registered in the object pool.
getObject<T>()Returns one object of type T that is registered in the object pool. This respects Aggregation.
getObjectByName(const QString &name)Returns one object with the given object name that is registered in the object pool.
SignalDescription
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 getObject() function. It is aware of Aggregation::Aggregate, and uses the Aggregation::query() function instead of qobject_cast to determine the matching objects.

An unfiltered list of all objects that are registered in the object pool can be retrieved via the allObjects() function.

It is also possible to retrieve an object with a specific object name with getObjectByName() (see QObject::objectName()).

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.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.