Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QPluginLoader Class Reference
[QtCore module]

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

 #include <QPluginLoader>

Inherits QObject.

Note: All the functions in this class are reentrant.

Properties

  • 1 property inherited from QObject

Public Functions

  • 29 public functions inherited from QObject

Static Public Members

  • 5 static public members inherited from QObject

Related Non-Members

Additional Inherited Members

  • 1 public slot inherited from QObject
  • 1 signal inherited from QObject
  • 7 protected functions inherited from QObject

Detailed Description

The QPluginLoader class loads a plugin at run-time.

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 happen, the root component will also be deleted.

In order to speed up loading and validation of plugins, some of the information that is collected during loading is cached in persistent memory (through QSettings). For instance, the result of a load operation (e.g. succeeded or failed) is stored in the cache, so that subsequent load operations don't try to load an invalid plugin. However, if the "last modified" timestamp of a plugin has changed, the plugin's cache entry is invalidated and the plugin is reloaded regardless of the values in the cache entry. The cache entry is then updated with the new result of the load operation.

This also means that the timestamp must be updated each time the plugin or any dependent resources (such as a shared library) is updated, since the dependent resources might influence the result of loading a plugin.

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.

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 Mac OS X, and .dll on Windows. The suffix can be verified with QLibrary::isLibrary().

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

This property holds 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, none of the hints are 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.


Member Function Documentation

QPluginLoader::QPluginLoader ( QObject * parent = 0 )

Constructs a plugin loader with the given parent.

QPluginLoader::QPluginLoader ( const QString & fileName, QObject * parent = 0 )

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 Mac OS X, and .dll on Windows. The suffix can be verified with QLibrary::isLibrary().

See also setFileName().

QPluginLoader::~QPluginLoader ()

Destroys the QPluginLoader object.

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

See also isLoaded() and unload().

QString QPluginLoader::errorString () const

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

This function was introduced in Qt 4.2.

QObject * QPluginLoader::instance ()

Returns the root component object of the plugin. The plugin is loaded if necessary. The function returns 0 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 QPluginLoader is destroyed. If you want to ensure that the root component is deleted, you should call unload() 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 QObject. Use qobject_cast() to access interfaces you are interested in.

See also load().

bool QPluginLoader::isLoaded () const

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

See also load().

bool QPluginLoader::load ()

Loads the plugin and returns true if the plugin was loaded successfully; otherwise returns false. Since instance() 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 unload().

QObjectList QPluginLoader::staticInstances ()   [static]

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

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 QPluginLoader 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 instance() and load().


Related Non-Members

void qRegisterStaticPluginInstanceFunction ( QtPluginInstanceFunction function )

Registers the given function with the plugin loader.

This function was introduced in Qt 4.4.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 53
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  4. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.5
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web