class KPluginLoader


Module kdecore
Namespace
Class KPluginLoader
Inherits QPluginLoader
\class KPluginLoader kpluginloader.h

This class can be used to dynamically load a plugin library at runtime.

This class makes sure that the Qt and KDE versions used to compile this library aren't newer then the ones currently used.

This class is reentrant, you can load plugins from different threads. You can also have multiple PluginLoaders for one library without negative effects. The object obtained with factory() or the inherited method QPluginLoader.instance() is cached inside the library. If you call factory() or instance() multiple times, you will always get the same object, even from different threads and different KPluginLoader instances. You can delete this object easily, a new one will be created if factory() or instance() is called afterwards. factory() uses instance() internally.

KPluginLoader inherits QPluginLoader.unload(). It safe to call this method if you loaded a plugin and decide not to use it for some reason. But as soon as you start to use the factory from the plugin, you should stay away from it. It's nearly impossible to keep track of all objects created directly or indirectly from the plugin and all other pointers into plugin code. Using unload() in this case is asking for trouble. If you really need to unload your plugins, you have to take care to convert the clipboard content to text, because the plugin could have registered a custom mime source. You also have to delete the factory of the plugin, otherwise you will create a leak. The destructor of KPluginLoader doesn't call unload.

Sample code:

KPluginLoader loader( ...library or kservice... );
KPluginFactory* factory = loader.factory();
if (!factory) {
kWarning() << "Error loading plugin:" << loader.errorString();
} else {
MyInterface* obj = factory->create();
if (!obj) {
kWarning() << "Error creating object";
}
}

See also KPluginFactory

Author Bernhard Loos



methods