QPluginLoader Class
The QPluginLoader class loads a plugin at run-time. More...
| Header: | #include <QPluginLoader> |
| qmake: | QT += core |
| Inherits: | QObject |
Note: All functions in this class are reentrant.
Properties
Public Functions
| QString | fileName() const |
| QLibrary::LoadHints | loadHints() const |
| void | setFileName(const QString &fileName) |
| void | setLoadHints(QLibrary::LoadHints loadHints) |
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 and Plug & Paint Example.
Property Documentation
fileName : QString
This property holds the file name of the plugin
We recommend omitting the file's suffix in the file name, since QPluginLoader will automatically look for the file with the appropriate suffix (see QLibrary::isLibrary()).
When loading the plugin, QPluginLoader searches in all plugin locations specified by QCoreApplication::libraryPaths(), unless the file name has an absolute path. After loading the plugin successfully, fileName() returns the fully-qualified file name of the plugin, including the full path to the plugin if one was given in the constructor or passed to setFileName().
If the file name does not exist, it will not be set. This property will then contain an empty string.
By default, this property contains an empty string.
Access functions:
| QString | fileName() const |
| void | setFileName(const QString &fileName) |
See also load().
loadHints : QLibrary::LoadHints
Give the load() function some hints on how it should behave.
You can give hints on how the symbols in the plugin are resolved. By default since Qt 5.7, QLibrary::PreventUnloadHint is set.
See the documentation of QLibrary::loadHints for a complete description of how this property works.
This property was introduced in Qt 4.4.
Access functions:
| QLibrary::LoadHints | loadHints() const |
| void | setLoadHints(QLibrary::LoadHints loadHints) |
See also QLibrary::loadHints.