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

KDECore

Public Member Functions | Protected Member Functions | Properties | Related Functions | List of all members
KPluginLoader Class Reference

#include <KPluginLoader>

Inheritance diagram for KPluginLoader:
Inheritance graph
[legend]

Public Member Functions

 KPluginLoader (const QString &plugin, const KComponentData &componentdata=KGlobal::mainComponent(), QObject *parent=0)
 
 KPluginLoader (const KService &service, const KComponentData &componentdata=KGlobal::mainComponent(), QObject *parent=0)
 
 ~KPluginLoader ()
 
QString errorString () const
 
KPluginFactory * factory ()
 
bool isLoaded () const
 
QString pluginName () const
 
quint32 pluginVersion () const
 
- Public Member Functions inherited from QPluginLoader
 QPluginLoader (QObject *parent)
 
 QPluginLoader (const QString &fileName, QObject *parent)
 
 ~QPluginLoader ()
 
QString errorString () const
 
QString fileName () const
 
QObject * instance ()
 
bool isLoaded () const
 
bool load ()
 
QLibrary::LoadHints loadHints () const
 
void setFileName (const QString &fileName)
 
void setLoadHints (QFlags< QLibrary::LoadHint > loadHints)
 
bool unload ()
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual  ~QObject ()
 
bool blockSignals (bool block)
 
QObject * child (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArray > dynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
T findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObject * metaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObject * parent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThread * thread () const
 

Protected Member Functions

bool load ()
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Properties

QString fileName
 
QString pluginName
 
- Properties inherited from QPluginLoader
 fileName
 
 loadHints
 
- Properties inherited from QObject
 objectName
 

Related Functions

(Note that these are not member functions.)

#define K_EXPORT_PLUGIN(factory)
 
#define K_EXPORT_PLUGIN_VERSION(version)   Q_EXTERN_C KDE_EXPORT const quint32 kde_plugin_version = version;
 

Additional Inherited Members

- Static Public Member Functions inherited from QPluginLoader
QObjectList staticInstances ()
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 

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 than 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 is 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..nosp@m.put@.nosp@m.web.d.nosp@m.e

Definition at line 79 of file kpluginloader.h.

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.

errorString() will be set if problems are encountered.

Parameters
pluginThe name of the plugin library.
componentdataThe KStandardDirs object from componentdata is used to search the library.
parentA parent object.

Definition at line 133 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.

errorString() will be set if problems are encountered.

Parameters
serviceThe service for which the library should be loaded.
componentdataThe KStandardDirs object from componentdata is used to search the library.
parentA parent object.

Definition at line 150 of file kpluginloader.cpp.

KPluginLoader::~KPluginLoader ( )

Destroys the plugin loader.

Definition at line 180 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 259 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 185 of file kpluginloader.cpp.

bool KPluginLoader::isLoaded ( ) const

Definition at line 128 of file kpluginloader.cpp.

bool KPluginLoader::load ( )
protected

Performs the loading of the plugin.

Definition at line 217 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 269 of file kpluginloader.cpp.

Friends And Related Function Documentation

#define K_EXPORT_PLUGIN (   factory)
related
Value:
Q_EXPORT_PLUGIN(factory) \
K_PLUGIN_VERIFICATION_DATA

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 71 of file kexportplugin.h.

#define K_EXPORT_PLUGIN_VERSION (   version)    Q_EXTERN_C KDE_EXPORT const quint32 kde_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 61 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
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal