IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QPluginLoader Class

The https:// class loads a plugin at run-time.

All functions in this class are https://.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QPluginLoader Class▲

  • Header: QPluginLoader

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Inherits: https://

  • Group: QPluginLoader is part of https://

Detailed Description▲

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

  • https:// checks that a plugin is linked against the same version of Qt as the application.

  • https:// provides direct access to a root component object (https://()), instead of forcing you to resolve a C function manually.

An instance of a https:// 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 https://().

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

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

See https:// for more information about how to make your application extensible through plugins.

Note that the https:// 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 https:// if you need to load dynamic libraries in a statically linked application.

See Also▲

See also https://, 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 https:// will automatically look for the file with the appropriate suffix (see https://()).

When loading the plugin, https:// searches in all plugin locations specified by https://(), 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:

  • fileName() const

  • void setFileName(const &fileName)

See Also▲

See also https://()

loadHints : QLibrary::LoadHints▲

Give the https://() 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, https:// is set.

See the documentation of https:// for a complete description of how this property works.

Access functions:

  • loadHints() const

  • void setLoadHints( loadHints)

See Also▲

See also https://

Member Function Documentation▲

 

[explicit] QPluginLoader::QPluginLoader(QObject *parent = nullptr)▲

Constructs a plugin loader with the given parent.

[explicit] QPluginLoader::QPluginLoader(const QString &fileName, QObject *parent = nullptr)▲

Constructs a plugin loader with the given parent that will load the plugin specified by fileName.

To be loadable, the file's suffix must be a valid suffix for a loadable library in accordance with the platform, e.g. .so on Unix, - .dylib on macOS and iOS, and .dll on Windows. The suffix can be verified with https://().

See Also▲

See also https://()

[virtual] QPluginLoader::~QPluginLoader()▲

Destroys the https:// object.

Unless https://() was called explicitly, the plugin stays in memory until the application terminates.

See Also▲

See also https://(), https://()

QString QPluginLoader::errorString() const▲

Returns a text string with the description of the last error that occurred.

QObject *QPluginLoader::instance()▲

Returns the root component object of the plugin. The plugin is loaded if necessary. The function returns nullptr if the plugin could not be loaded or if the root component object could not be instantiated.

If the root component object was destroyed, calling this function creates a new instance.

The root component, returned by this function, is not deleted when the https:// is destroyed. If you want to ensure that the root component is deleted, you should call https://() as soon you don't need to access the core component anymore. When the library is finally unloaded, the root component will automatically be deleted.

The component object is a https://. Use https://() to access interfaces you are interested in.

See Also▲

See also https://()

bool QPluginLoader::isLoaded() const▲

Returns true if the plugin is loaded; otherwise returns false.

See Also▲

See also https://()

bool QPluginLoader::load()▲

Loads the plugin and returns true if the plugin was loaded successfully; otherwise returns false. Since https://() always calls this function before resolving any symbols it is not necessary to call it explicitly. In some situations you might want the plugin loaded in advance, in which case you would use this function.

See Also▲

See also https://()

QJsonObject QPluginLoader::metaData() const▲

Returns the meta data for this plugin. The meta data is data specified in a json format using the https://() macro when compiling the plugin.

The meta data can be queried in a fast and inexpensive way without actually loading the plugin. This makes it possible to e.g. store capabilities of the plugin in there, and make the decision whether to load the plugin dependent on this meta data.

[static] QObjectList QPluginLoader::staticInstances()▲

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

See Also▲

See also https://()

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

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

See Also▲

See also https://()

bool QPluginLoader::unload()▲

Unloads the plugin and returns true if the plugin could be unloaded; otherwise returns false.

This happens automatically on application termination, so you shouldn't normally need to call this function.

If other instances of https:// are using the same plugin, the call will fail, and unloading will only happen when every instance has called unload().

Don't try to delete the root component. Instead rely on that unload() will automatically delete it when needed.

See Also▲

See also https://(), https://()

Related Non-Members▲

 

void qRegisterStaticPluginFunction(QStaticPlugin plugin)▲

Registers the plugin specified with the plugin loader, and is used by https://().

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.