- Qt 6.9
- Qt Core
- C++ Classes
- QPluginLoader
- Qt 6.9.2 Reference Documentation

# QPluginLoader Class

The QPluginLoader class loads a plugin at run-time. More...

Header: | `#include <QPluginLoader>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`

- List of all members, including inherited members
- QPluginLoader is part of Plugin Classes.

Note: All functions in this class are reentrant.

## Static Public Members

QObjectList | staticInstances()
QList<QStaticPlugin> | staticPlugins()

## Related Non-Members

void | qRegisterStaticPluginFunction(QStaticPlugin plugin)

## Detailed Description

QPluginLoader provides access to a Qt plugin. A Qt plugin is stored in a shared library (a DLL) and offers these benefits over shared libraries accessed using QLibrary:

- QPluginLoader checks that a plugin is linked against the same version of Qt as the application.
- QPluginLoader provides direct access to a root component object (instance()), instead of forcing you to resolve a C function manually.

An instance of a QPluginLoader object operates on a single shared library file, which we call a plugin. It provides access to the functionality in the plugin in a platform-independent way. To specify which plugin to load, either pass a file name in the constructor or set it with setFileName().

The most important functions are load() to dynamically load the plugin file, isLoaded() to check whether loading was successful, and instance() to access the root component in the plugin. The instance() function implicitly tries to load the plugin if it has not been loaded yet. Multiple instances of QPluginLoader can be used to access the same physical plugin.

Once loaded, plugins remain in memory until all instances of QPluginLoader has been unloaded, or until the application terminates. You can attempt to unload a plugin using unload(), but if other instances of QPluginLoader are using the same library, the call will fail, and unloading will only happen when every instance has called unload(). Right before the unloading happens, the root component will also be deleted.

See How to Create Qt Plugins for more information about how to make your application extensible through plugins.

Note that the QPluginLoader cannot be used if your application is statically linked against Qt. In this case, you will also have to link to plugins statically. You can use QLibrary if you need to load dynamic libraries in a statically linked application.

See also QLibrary.

## Member Function Documentation

### `[static]` QObjectList QPluginLoader::staticInstances()

Returns a list of static plugin instances (root components) held by the plugin loader.

See also staticPlugins().

### `[static]` QList<QStaticPlugin> QPluginLoader::staticPlugins()

Returns a list of QStaticPlugins held by the plugin loader. The function is similar to staticInstances() with the addition that a QStaticPlugin also contains meta data information.

See also staticInstances().

## Related Non-Members

### void qRegisterStaticPluginFunction(QStaticPlugin plugin)

Registers the plugin specified with the plugin loader, and is used by Q_IMPORT_PLUGIN().