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

KDECore

Classes | Signals | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Related Functions | List of all members
KPluginFactory Class Reference

#include <KPluginFactory>

Inheritance diagram for KPluginFactory:
Inheritance graph
[legend]

Classes

struct  InheritanceChecker
 

Signals

void objectCreated (QObject *object)
 

Public Member Functions

 KPluginFactory (const char *componentName=0, const char *catalogName=0, QObject *parent=0)
 
 KPluginFactory (const KAboutData &aboutData, QObject *parent=0)
 
KDE_CONSTRUCTOR_DEPRECATED KPluginFactory (const KAboutData *aboutData, QObject *parent=0)
 
KDE_CONSTRUCTOR_DEPRECATED KPluginFactory (QObject *parent)
 
virtual ~KPluginFactory ()
 
KComponentData componentData () const
 
template<typename T >
T * create (QObject *parent=0, const QVariantList &args=QVariantList())
 
template<typename T >
T * create (const QString &keyword, QObject *parent=0, const QVariantList &args=QVariantList())
 
template<typename T >
T * create (QWidget *parentWidget, QObject *parent, const QString &keyword=QString(), const QVariantList &args=QVariantList())
 
template<typename T >
T * create (QObject *parent, const QStringList &args)
 
QObject * create (QObject *parent=0, const char *classname="QObject", const QStringList &args=QStringList())
 
- 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 Types

typedef QObject *(* CreateInstanceFunction )(QWidget *, QObject *, const QVariantList &)
 

Protected Member Functions

 KPluginFactory (KPluginFactoryPrivate &dd, QObject *parent=0)
 
virtual QObject * create (const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
 
virtual QObject * createObject (QObject *parent, const char *className, const QStringList &args)
 
virtual KParts::Part * createPartObject (QWidget *parentWidget, QObject *parent, const char *classname, const QStringList &args)
 
template<class T >
void registerPlugin (const QString &keyword=QString(), CreateInstanceFunction instanceFunction=InheritanceChecker< T >().createInstanceFunction(reinterpret_cast< T * >(0)))
 
void setComponentData (const KComponentData &componentData)
 
virtual void setupTranslations ()
 
QVariantList stringListToVariantList (const QStringList &list)
 
QStringList variantListToStringList (const QVariantList &list)
 
- 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)
 

Static Protected Member Functions

template<class impl , class ParentType >
static QObject * createInstance (QWidget *parentWidget, QObject *parent, const QVariantList &args)
 
template<class impl >
static QObject * createPartInstance (QWidget *parentWidget, QObject *parent, const QVariantList &args)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 

Protected Attributes

KPluginFactoryPrivate *const d_ptr
 

Related Functions

(Note that these are not member functions.)

#define K_PLUGIN_FACTORY(name, pluginRegistrations)   K_PLUGIN_FACTORY_WITH_BASEFACTORY(name, KPluginFactory, pluginRegistrations)
 
#define K_PLUGIN_FACTORY_DECLARATION(name)   K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY(name, KPluginFactory)
 
#define K_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations)   K_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name, KPluginFactory, pluginRegistrations)
 

Additional Inherited Members

- 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)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

If you develop a library that is to be loaded dynamically at runtime, then you should return a pointer to a KPluginFactory.

For most cases it is enough to use the K_PLUGIN_FACTORY macro to create the factory.

Example:

#include <KPluginFactory>
#include <KPluginLoader>
#include <plugininterface.h>
class MyPlugin;
K_PLUGIN_FACTORY(MyPluginFactory,
registerPlugin<MyPlugin>();
)
K_EXPORT_PLUGIN(MyPluginFactory("componentName"))
class MyPlugin : public PluginInterface
{
...
KComponentData kcd = MyPluginFactory::componentData();
...
};

K_PLUGIN_FACTORY is a convenient macro that expands to a class derived from KPluginFactory providing two constructors and a static componentData() function. The second argument to K_PLUGIN_FACTORY is code that is called from the constructors. There you can use registerPlugin to register as many plugins for the factory as you want to.

If you want to write a custom KPluginFactory not using the standard macro(s) you can reimplement the create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword) function.

Example:

class SomeScriptLanguageFactory : public KPluginFactory
{
Q_OBJECT
public:
SomeScriptLanguageFactory()
: KPluginFactory("SomeScriptLanguageComponent")
{}
protected:
virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
{
const QString identifier = QLatin1String(iface) + QLatin1Char('_') + keyword;
// load scripting language module from the information in identifier
// and return it:
return object;
}
};

If you want to load a library use KPluginLoader. The application that wants to instantiate plugin classes can do the following:

KPluginFactory *factory = KPluginLoader("libraryname").factory();
if (factory) {
PluginInterface *p1 = factory->create<PluginInterface>(parent);
OtherInterface *p2 = factory->create<OtherInterface>(parent);
NextInterface *p3 = factory->create<NextInterface>("keyword1", parent);
NextInterface *p3 = factory->create<NextInterface>("keyword2", parent);
}
Author
Matthias Kretz kretz.nosp@m.@kde.nosp@m..org
Bernhard Loos nhuh..nosp@m.put@.nosp@m.web.d.nosp@m.e

Definition at line 232 of file kpluginfactory.h.

Member Typedef Documentation

typedef QObject*(* KPluginFactory::CreateInstanceFunction)(QWidget *, QObject *, const QVariantList &)
protected

Function pointer type to a function that instantiates a plugin.

Definition at line 366 of file kpluginfactory.h.

Constructor & Destructor Documentation

KPluginFactory::KPluginFactory ( const char *  componentName = 0,
const char *  catalogName = 0,
QObject *  parent = 0 
)
explicit

This constructor creates a factory for a plugin with the given componentName and catalogName.

Those values are used to initialize a KComponentData object for the plugin. You can later access it with componentData(). If componentName is 0, an invalid KComponentData object will be created.

Parameters
componentNamethe component name of the plugin
catalogNamethe translation catalog to use
parenta parent object

Definition at line 33 of file kpluginfactory.cpp.

KPluginFactory::KPluginFactory ( const KAboutData &  aboutData,
QObject *  parent = 0 
)
explicit

This constructor creates a factory for a plugin with the given KAboutData object.

This object is used to initialize a KComponentData object for the plugin. You can later access it with componentData(). KPluginFactory takes ownership of the aboutData object, so don't delete it yourself!

Parameters
aboutDatathe KAboutData for the plugin
parenta parent object

Definition at line 57 of file kpluginfactory.cpp.

KPluginFactory::KPluginFactory ( const KAboutData *  aboutData,
QObject *  parent = 0 
)
explicit
Deprecated:

Definition at line 46 of file kpluginfactory.cpp.

KPluginFactory::KPluginFactory ( QObject *  parent)
explicit
Deprecated:

Definition at line 68 of file kpluginfactory.cpp.

KPluginFactory::~KPluginFactory ( )
virtual

This destroys the PluginFactory.

It will remove the translation catalog for the plugin, if it was initialized.

Definition at line 83 of file kpluginfactory.cpp.

KPluginFactory::KPluginFactory ( KPluginFactoryPrivate &  dd,
QObject *  parent = 0 
)
explicitprotected

Definition at line 77 of file kpluginfactory.cpp.

Member Function Documentation

KComponentData KPluginFactory::componentData ( ) const

You can use this method to get the component data of the plugin.

It is filled with the information given to the constructor of KPluginFactory. The K_PLUGIN_FACTORY macros provide a static version of this method, this can be used from any place within the plugin.

Only use this method if you specified a componentData name or instance to the factory constructor or to setComponentData. Otherwise you get an invalid KComponentData, which will crash if used.

Returns
The KComponentData for the plugin

Definition at line 94 of file kpluginfactory.cpp.

template<typename T >
T * KPluginFactory::create ( QObject *  parent = 0,
const QVariantList &  args = QVariantList() 
)
inline

Use this method to create an object.

It will try to create an object which inherits T. If it has multiple choices, you will get a fatal error (kFatal()), so be careful to request a unique interface or use keywords.

Template Parameters
TThe interface for which an object should be created. The object will inherit T.
Parameters
parentThe parent of the object. If parent is a widget type, it will also passed to the parentWidget argument of the CreateInstanceFunction for the object.
argsAdditional arguments which will be passed to the object.
Returns
A pointer to the created object is returned, or 0 if an error occurred.

Definition at line 505 of file kpluginfactory.h.

template<typename T >
T * KPluginFactory::create ( const QString &  keyword,
QObject *  parent = 0,
const QVariantList &  args = QVariantList() 
)
inline

Use this method to create an object.

It will try to create an object which inherits T and was registered with keyword.

Template Parameters
TThe interface for which an object should be created. The object will inherit T.
Parameters
keywordThe keyword of the object.
parentThe parent of the object. If parent is a widget type, it will also passed to the parentWidget argument of the CreateInstanceFunction for the object.
argsAdditional arguments which will be passed to the object.
Returns
A pointer to the created object is returned, or 0 if an error occurred.

Definition at line 517 of file kpluginfactory.h.

template<typename T >
T * KPluginFactory::create ( QWidget *  parentWidget,
QObject *  parent,
const QString &  keyword = QString(),
const QVariantList &  args = QVariantList() 
)
inline

Use this method to create an object.

It will try to create an object which inherits T and was registered with keyword. This overload has an additional parentWidget argument, which is used by some plugins (e.g. Parts).

Template Parameters
TThe interface for which an object should be created. The object will inherit T.
Parameters
parentWidgetAn additional parent widget.
parentThe parent of the object. If parent is a widget type, it will also passed to the parentWidget argument of the CreateInstanceFunction for the object.
keywordThe keyword of the object.
argsAdditional arguments which will be passed to the object.
Returns
A pointer to the created object is returned, or 0 if an error occurred.

Definition at line 529 of file kpluginfactory.h.

template<typename T >
T* KPluginFactory::create ( QObject *  parent,
const QStringList &  args 
)
inline
Deprecated:

Definition at line 343 of file kpluginfactory.h.

QObject* KPluginFactory::create ( QObject *  parent = 0,
const char *  classname = "QObject",
const QStringList &  args = QStringList() 
)
inline
Deprecated:

Definition at line 353 of file kpluginfactory.h.

QObject * KPluginFactory::create ( const char *  iface,
QWidget *  parentWidget,
QObject *  parent,
const QVariantList &  args,
const QString &  keyword 
)
protectedvirtual

This function is called when the factory asked to create an Object.

You may reimplement it to provide a very flexible factory. This is especially useful to provide generic factories for plugins implemeted using a scripting language.

Parameters
ifaceThe staticMetaObject::className() string identifying the plugin interface that was requested. E.g. for KCModule plugins this string will be "KCModule".
parentWidgetOnly used if the requested plugin is a KPart.
parentThe parent object for the plugin object.
argsA plugin specific list of arbitrary arguments.
keywordA string that uniquely identifies the plugin. If a KService is used this keyword is read from the X-KDE-PluginKeyword entry in the .desktop file.

Definition at line 161 of file kpluginfactory.cpp.

template<class impl , class ParentType >
static QObject* KPluginFactory::createInstance ( QWidget *  parentWidget,
QObject *  parent,
const QVariantList &  args 
)
inlinestaticprotected

Definition at line 469 of file kpluginfactory.h.

QObject * KPluginFactory::createObject ( QObject *  parent,
const char *  className,
const QStringList &  args 
)
protectedvirtual
Deprecated:

Reimplemented in KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >, KGenericFactory< KTypeList< Product, ProductListTail >, QObject >, and KGenericFactory< Product, ParentType >.

Definition at line 141 of file kpluginfactory.cpp.

template<class impl >
static QObject* KPluginFactory::createPartInstance ( QWidget *  parentWidget,
QObject *  parent,
const QVariantList &  args 
)
inlinestaticprotected

Definition at line 481 of file kpluginfactory.h.

KParts::Part * KPluginFactory::createPartObject ( QWidget *  parentWidget,
QObject *  parent,
const char *  classname,
const QStringList &  args 
)
protectedvirtual
Deprecated:

Definition at line 151 of file kpluginfactory.cpp.

void KPluginFactory::objectCreated ( QObject *  object)
signal
template<class T >
void KPluginFactory::registerPlugin ( const QString &  keyword = QString(),
CreateInstanceFunction  instanceFunction = InheritanceChecker<T>().createInstanceFunction(reinterpret_cast<T *>(0)) 
)
inlineprotected

Registers a plugin with the factory.

Call this function from the constructor of the KPluginFactory subclass to make the create function able to instantiate the plugin when asked for an interface the plugin implements.

You can register as many plugin classes as you want as long as either the plugin interface or the keyword makes it unique. E.g. it is possible to register a KCModule and a KParts::Part without having to specify keywords since their interfaces differ.

Template Parameters
Tthe name of the plugin class
Parameters
keywordAn optional keyword as unique identifier for the plugin. This allows you to put more than one plugin with the same interface into the same library using the same factory. X-KDE-PluginKeyword is a convenient way to specify the keyword in a desktop file.
instanceFunctionA function pointer to a function that creates an instance of the plugin. The default function that will be used depends on the type of interface. If the interface inherits from
  • KParts::Part the function will call
    new T(QWidget *parentWidget, QObject *parent, const QVariantList &args)
  • QWidget the function will call
    new T(QWidget *parent, const QVariantList &args)
  • else the function will call
    new T(QObject *parent, const QVariantList &args)

Definition at line 402 of file kpluginfactory.h.

void KPluginFactory::setComponentData ( const KComponentData &  componentData)
protected

This method sets the component data of the plugin.

You can access the component data object later with componentData(). Normally you don't have to call this, because the factory constructs a component data object from the information given to the constructor. The object is destroyed, when the module containing the plugin is unloaded. Normally this happens only on application shutdown.

Parameters
componentDatathe new KComponentData object

Definition at line 225 of file kpluginfactory.cpp.

void KPluginFactory::setupTranslations ( )
protectedvirtual

Definition at line 215 of file kpluginfactory.cpp.

QVariantList KPluginFactory::stringListToVariantList ( const QStringList &  list)
protected

Converts a QStringList to a QVariantList

Definition at line 241 of file kpluginfactory.cpp.

QStringList KPluginFactory::variantListToStringList ( const QVariantList &  list)
protected

Converts a QVariantList of strings to a QStringList

Definition at line 232 of file kpluginfactory.cpp.

Friends And Related Function Documentation

#define K_PLUGIN_FACTORY (   name,
  pluginRegistrations 
)    K_PLUGIN_FACTORY_WITH_BASEFACTORY(name, KPluginFactory, pluginRegistrations)
related

Defines a KPluginFactory subclass with two constructors and a static componentData function.

The first constructor takes the arguments (const char *componentName, const char *catalogName, QObject *parent). The second constructor takes (const KAboutData *aboutData, QObject *parent).

The static componentData method returns the same KComponentData object as the KPluginFactory::componentData function returns. As you normally don't have a pointer to the factory object in the plugin code the static componentData function is a convenient way to access the KComponentData.

Parameters
nameThe name of the KPluginFactory derived class. This is the name you'll need for K_EXPORT_PLUGIN
pluginRegistrationsThis is code inserted into the constructors the class. You'll want to call registerPlugin from there.

Example:

#include <KPluginFactory>
#include <KPluginLoader>
#include <plugininterface.h>
class MyPlugin;
K_PLUGIN_FACTORY(MyPluginFactory,
registerPlugin<MyPlugin>();
)
K_EXPORT_PLUGIN(MyPluginFactory("componentName", "catalogName"))
// or:
static KAboutData createAboutData()
{
KAboutData aboutData("myplugin", "myplugin", ki18n("MyPlugin"), "0.1",
ki18n("a description of the plugin"), KAboutData::License_LGPL,
ki18n("Copyright (C) 2007 Your Name"));
aboutData.addAuthor(ki18n("Your Name"), ...);
return aboutData;
}
K_EXPORT_PLUGIN(MyPluginFactory(createAboutData()))
class MyPlugin : public PluginInterface
{
...
KComponentData kcd = MyPluginFactory::componentData();
...
};
See also
K_PLUGIN_FACTORY_DECLARATION
K_PLUGIN_FACTORY_DEFINITION

Definition at line 127 of file kpluginfactory.h.

#define K_PLUGIN_FACTORY_DECLARATION (   name)    K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY(name, KPluginFactory)
related

K_PLUGIN_FACTORY_DECLARATION declares the KPluginFactory subclass. This macro can be used in a header file.

Parameters
nameThe name of the KPluginFactory derived class. This is the name you'll need for K_EXPORT_PLUGIN
See also
K_PLUGIN_FACTORY
K_PLUGIN_FACTORY_DEFINITION

Definition at line 140 of file kpluginfactory.h.

#define K_PLUGIN_FACTORY_DEFINITION (   name,
  pluginRegistrations 
)    K_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name, KPluginFactory, pluginRegistrations)
related

K_PLUGIN_FACTORY_DEFINITION defines the KPluginFactory subclass. This macro can not be used in a header file.

Parameters
nameThe name of the KPluginFactory derived class. This is the name you'll need for K_EXPORT_PLUGIN
pluginRegistrationsThis is code inserted into the constructors the class. You'll want to call registerPlugin from there.
See also
K_PLUGIN_FACTORY
K_PLUGIN_FACTORY_DECLARATION

Definition at line 156 of file kpluginfactory.h.

Member Data Documentation

KPluginFactoryPrivate* const KPluginFactory::d_ptr
protected

Definition at line 422 of file kpluginfactory.h.


The documentation for this class was generated from the following files:
  • kpluginfactory.h
  • kpluginfactory.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