• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

KPluginLoader Class Reference

#include <KPluginLoader>

Inheritance diagram for KPluginLoader:

Inheritance graph
[legend]

List of all members.


Detailed Description

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<MyInterface>();
      if (!obj) {
          kWarning() << "Error creating object";
      }
  }

See also:
KPluginFactory
Author:
Bernhard Loos <nhuh.put@web.de>

Definition at line 79 of file kpluginloader.h.


Public Member Functions

QString errorString () const
KPluginFactory * factory ()
bool isLoaded () const
 KPluginLoader (const KService &service, const KComponentData &componentdata=KGlobal::mainComponent(), QObject *parent=0)
 KPluginLoader (const QString &plugin, const KComponentData &componentdata=KGlobal::mainComponent(), QObject *parent=0)
QString pluginName () const
quint32 pluginVersion () const
 ~KPluginLoader ()

Protected Member Functions

bool load ()

Properties

QString fileName
QString pluginName

Related Functions

(Note that these are not member functions.)

 K_EXPORT_PLUGIN(factory)
 K_EXPORT_PLUGIN_VERSION(version)

Constructor & Destructor Documentation

KPluginLoader::KPluginLoader ( const QString &  plugin,
const KComponentData &  componentdata = KGlobal::mainComponent(),
QObject *  parent = 0 
) [explicit]

Used this constructor to load a plugin with a given library name.

Plugin libraries shouldn't have a 'lib' prefix.

Parameters:
plugin The name of the plugin library.
componentdata The KStandardDirs object from componentdata is used to search the library.
parent A parent object.

Definition at line 116 of file kpluginloader.cpp.

KPluginLoader::KPluginLoader ( const KService &  service,
const KComponentData &  componentdata = KGlobal::mainComponent(),
QObject *  parent = 0 
) [explicit]

Used this constructor to load a plugin from a service.

The service must contain a library.

Parameters:
service The service for which the library should be loaded.
componentdata The KStandardDirs object from componentdata is used to search the library.
parent A parent object.

Definition at line 123 of file kpluginloader.cpp.

KPluginLoader::~KPluginLoader (  ) 

Destroys the plugin loader.

Definition at line 137 of file kpluginloader.cpp.


Member Function Documentation

QString KPluginLoader::errorString (  )  const

Queries the last error.

Returns:
The description of the last error.

Definition at line 207 of file kpluginloader.cpp.

KPluginFactory * KPluginLoader::factory (  ) 

Used to obtain the factory object of the plugin.

You have to give a class which inherits KPluginFactory to K_EXPORT_PLUGIN to use this method.

Returns:
The factory of the plugin or 0 on error.

Definition at line 142 of file kpluginloader.cpp.

bool KPluginLoader::isLoaded (  )  const

Definition at line 111 of file kpluginloader.cpp.

bool KPluginLoader::load (  )  [protected]

Performs the loading of the plugin.

Reimplemented from QPluginLoader.

Definition at line 169 of file kpluginloader.cpp.

QString KPluginLoader::pluginName (  )  const

The name of this plugin as given to the constructor.

Returns:
the plugin name

quint32 KPluginLoader::pluginVersion (  )  const

Queries the plugin version.

Returns:
The version given to K_EXPORT_PLUGIN_VERSION or (quint32) -1 if not set.

Definition at line 216 of file kpluginloader.cpp.


Friends And Related Function Documentation

K_EXPORT_PLUGIN ( factory   )  [related]

This macro exports the main object of the plugin.

Most times, this will be a KPluginFactory or derived class, but any QObject derived class can be used. Take a look at the documentation of Q_EXPORT_PLUGIN2 for some details.

Definition at line 68 of file kexportplugin.h.

K_EXPORT_PLUGIN_VERSION ( version   )  [related]

Use this macro if you want to give your plugin a version number.

You can later access the version number with KPluginLoader::pluginVersion()

Definition at line 58 of file kexportplugin.h.


Property Documentation

QString KPluginLoader::fileName [read]

Definition at line 82 of file kpluginloader.h.

QString KPluginLoader::pluginName [read]

Definition at line 83 of file kpluginloader.h.


The documentation for this class was generated from the following files:
  • kpluginloader.h
  • kexportplugin.h
  • kpluginloader.cpp

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal