kdecore Library API Documentation

KGenericFactory< Product, ParentType > Class Template Reference

This template provides a generic implementation of a KLibFactory , for use with shared library components. More...

#include <kgenericfactory.h>

Inheritance diagram for KGenericFactory< Product, ParentType >:

KLibFactory QObject List of all members.

Public Member Functions

 KGenericFactory (const char *instanceName=0)

Protected Member Functions

virtual QObjectcreateObject (QObject *parent, const char *name, const char *className, const QStringList &args)
 Creates a new object.


Detailed Description

template<class Product, class ParentType = QObject>
class KGenericFactory< Product, ParentType >

This template provides a generic implementation of a KLibFactory , for use with shared library components.

It implements the pure virtual createObject method of KLibFactory and instantiates objects of the specified class (template argument) when the class name argument of createObject matches a class name in the given hierarchy.

In case you are developing a KParts component, skip this file and go directly to KParts::GenericFactory .

Note that the class specified as template argument needs to provide a certain constructor:

The args QStringList passed to the constructor is the args string list that the caller passed to KLibFactory's create method.

In addition upon instantiation this template provides a central KInstance object for your component, accessible through the static instance() method. The instanceName argument of the KGenericFactory constructor is passed to the KInstance object.

The creation of the KInstance object can be customized by inheriting from this template class and re-implementing the virtual createInstance method. For example it could look like this:

KInstance *MyFactory::createInstance() { return new KInstance( myAboutData ); }

Example of usage of the whole template:

class MyPlugin : public KParts::Plugin { Q_ OBJECT public: MyPlugin( QObject *parent, const char *name, const QStringList &args ); ... };

K_EXPORT_COMPONENT_FACTORY( libmyplugin, KGenericFactory<MyPlugin> );

Definition at line 158 of file kgenericfactory.h.


Member Function Documentation

template<class Product, class ParentType = QObject>
virtual QObject* KGenericFactory< Product, ParentType >::createObject QObject parent,
const char *  name,
const char *  className,
const QStringList args
[inline, protected, virtual]
 

Creates a new object.

The returned object has to be derived from the requested classname.

It is valid behavior to create different kinds of objects depending on the requested classname. For example a koffice library may usually return a pointer to KoDocument. But if asked for a "QWidget", it could create a wrapper widget, that encapsulates the Koffice specific features.

This function is called by create()

Parameters:
parent the parent of the QObject, 0 for no parent
name the name of the QObject, 0 for no name
classname the name of the class
args a list of arguments

Implements KLibFactory.

Definition at line 166 of file kgenericfactory.h.

References KStdAction::name().


The documentation for this class was generated from the following file:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:14:50 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001