ExtensionSystem::IPlugin Class | Extending Qt Creator Manual
Description: The IPlugin class is an abstract base class that must be implemented once for each plugin.

- Extending Qt Creator Manual
- QtCreator
- IPlugin
- Extending Qt Creator Manual 19.0.0

# ExtensionSystem::IPlugin Class

class ExtensionSystem::IPlugin

The IPlugin class is an abstract base class that must be implemented once for each plugin. More...

Header: | `#include <extensionsystem/iplugin.h>`
Inherits: | QObject

- List of all members, including inherited members

## Public Types

enum | ShutdownFlag { SynchronousShutdown, AsynchronousShutdown }

## Public Functions

virtual ExtensionSystem::IPlugin::ShutdownFlag | aboutToShutdown()
void | addTestCreator(const ExtensionSystem::TestCreator &creator)
virtual bool | delayedInitialize()
virtual void | extensionsInitialized()
virtual Utils::Result<> | initialize(const QStringList &arguments)
virtual QObject * | remoteCommand(const QStringList &options, const QString &workingDirectory, const QStringList &arguments)

## Signals

void | asynchronousShutdownFinished()

## Protected Functions

virtual void | initialize()

## Detailed Description

A plugin needs to provide meta data in addition to the actual plugin library, so the plugin manager can find the plugin, resolve its dependencies, and load it. For more information, see Plugin Meta Data.

Plugins must provide one implementation of the IPlugin class, located in a library that matches the `name` attribute given in their meta data. The IPlugin implementation must be exported and made known to Qt's plugin system, using the `Q_PLUGIN_METADATA` macro with an IID set to `"org.qt-project.Qt.QtCreatorPlugin"`.

For more information, see Plugin Life Cycle.

## Member Type Documentation

### enum IPlugin::ShutdownFlag

This enum type holds whether the plugin is shut down synchronously or asynchronously.

Constant | Value | Description
--- | --- | ---
`ExtensionSystem::IPlugin::SynchronousShutdown` | `0` | The plugin is shut down synchronously.
`ExtensionSystem::IPlugin::AsynchronousShutdown` | `1` | The plugin needs to perform asynchronous actions before it shuts down.

## Member Function Documentation

### `[virtual]` ExtensionSystem::IPlugin::ShutdownFlag IPlugin::aboutToShutdown()

Called during a shutdown sequence in the same order as initialization before the plugins get deleted in reverse order.

This function should be used to disconnect from other plugins, hide all UI, and optimize shutdown in general. If a plugin needs to delay the real shutdown for a while, for example if it needs to wait for external processes to finish for a clean shutdown, the plugin can return IPlugin::AsynchronousShutdown from this function. This will keep the main event loop running after the aboutToShutdown() sequence has finished, until all plugins requesting asynchronous shutdown have sent the asynchronousShutdownFinished() signal.

The default implementation of this function does nothing and returns IPlugin::SynchronousShutdown.

Returns IPlugin::AsynchronousShutdown if the plugin needs to perform asynchronous actions before shutdown.

See also asynchronousShutdownFinished().

### void IPlugin::addTestCreator(const ExtensionSystem::TestCreator &creator)

Registers a function object that creates a test object with the owner creator.

The created objects are meant to be passed on to QTest::qExec().

The function objects will be called if the user starts Qt Creator with `-test PluginName` or `-test all`.

The ownership of the created object is transferred to the plugin.

### `[signal]` void IPlugin::asynchronousShutdownFinished()

Sent by the plugin implementation after an asynchronous shutdown is ready to proceed with the shutdown sequence.

See also aboutToShutdown().

### `[virtual]` bool IPlugin::delayedInitialize()

Called after all plugins' extensionsInitialized() function has been called, and after the `delayedInitialize()` function of plugins that depend on this plugin have been called.

The plugins' `delayedInitialize()` functions are called after the application is already running, with a few milliseconds delay to application startup, and between individual `delayedInitialize()` function calls. To avoid unnecessary delays, a plugin should return `true` from the function if it actually implements it, to indicate that the next plugins' `delayedInitialize()` call should be delayed a few milliseconds to give input and paint events a chance to be processed.

This function can be used if a plugin needs to do non-trivial setup that doesn't necessarily need to be done directly at startup, but still should be done within a short time afterwards. This can decrease the perceived plugin or application startup time a lot, with very little effort.

See also initialize() and extensionsInitialized().

### `[virtual]` void IPlugin::extensionsInitialized()

Called after the initialize() function has been called, and after both the initialize() and `extensionsInitialized()` functions of plugins that depend on this plugin have been called.

In this function, the plugin can assume that plugins that depend on this plugin are fully up and running. It is a good place to look in the global object pool for objects that have been provided by weakly dependent plugins.

See also initialize() and delayedInitialize().

### `[virtual protected]` void IPlugin::initialize()

This function is called as the default implementation of `initialize(const QStringList &arguments)` and can be overwritten instead of the full-args version in cases the parameters are not used by the implementation and there is no error to report.

See also extensionsInitialized() and delayedInitialize().

### `[virtual]` Utils::Result<> IPlugin::initialize(const QStringList &arguments)

Called after the plugin has been loaded and the IPlugin instance has been created.

The initialize functions of plugins that depend on this plugin are called after the initialize function of this plugin has been called with arguments. Plugins should initialize their internal state in this function.

Returns whether initialization succeeds.

See also extensionsInitialized() and delayedInitialize().

### `[virtual]` QObject *IPlugin::remoteCommand(const QStringList &options, const QString &workingDirectory, const QStringList &arguments)

When Qt Creator is executed with the `-client` argument while another Qt Creator instance is running, this function of the plugin is called in the running instance.

The workingDirectory argument specifies the working directory of the calling process. For example, if you're in a directory, and you execute `qtcreator -client file.cpp`, the working directory of the calling process is passed to the running instance and `file.cpp` is transformed into an absolute path starting from this directory.

Plugin-specific arguments are passed in options, while the rest of the arguments are passed in arguments.

Returns a QObject that blocks the command until it is destroyed, if `-block` is used.