kdecore Library API Documentation

KLibFactory Class Reference

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

#include <klibloader.h>

Inheritance diagram for KLibFactory:

Inheritance graph
[legend]
Collaboration diagram for KLibFactory:

Collaboration graph
[legend]
List of all members.

Signals

void objectCreated (QObject *obj)
 Emitted in create.


Public Member Functions

 KLibFactory (QObject *parent=0, const char *name=0)
 Create a new factory.

QObjectcreate (QObject *parent=0, const char *name=0, const char *classname="QObject", const QStringList &args=QStringList())
 Creates a new object.


Protected Member Functions

virtual QObjectcreateObject (QObject *parent=0, const char *name=0, const char *classname="QObject", const QStringList &args=QStringList())=0
 Creates a new object.

virtual void virtual_hook (int id, void *data)

Detailed Description

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

The K_EXPORT_COMPONENT_FACTORY macro is provided for this purpose:

K_EXPORT_COMPONENT_FACTORY( libkspread, KSpreadFactory )

The first macro argument is the name of your library, the second specifies the name of your factory.

In the constructor of your factory you should create an instance of KInstance like this:

s_global = new KInstance( "kspread" );
This KInstance is comparable to KGlobal used by normal applications. It allows you to find resource files (images, XML, sound etc.) belonging to the library.

If you want to load a library, use KLibLoader. You can query KLibLoader directly for a pointer to the libraries factory by using the KLibLoader::factory() function.

The KLibFactory is used to create the components, the library has to offer. The factory of KSpread for example will create instances of KSpreadDoc, while the Konqueror factory will create KonqView widgets. All objects created by the factory must be derived from QObject, since QObject offers type safe casting.

KLibFactory is an abstract class. Reimplement the createObject() method to give it functionality.

Author:
Torben Weis <weis@kde.org>

Definition at line 328 of file klibloader.h.


Constructor & Destructor Documentation

KLibFactory::KLibFactory QObject parent = 0,
const char *  name = 0
 

Create a new factory.

Parameters:
parent the parent of the QObject, 0 for no parent
name the name of the QObject, 0 for no name

Definition at line 66 of file klibloader.cpp.

References KStdAction::name().


Member Function Documentation

QObject * KLibFactory::create QObject parent = 0,
const char *  name = 0,
const char *  classname = "QObject",
const QStringList args = QStringList()
 

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.

create() automatically emits a signal objectCreated to tell the library about its newly created object. This is very important for reference counting, and allows unloading the library automatically once all its objects have been destroyed.

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

Definition at line 76 of file klibloader.cpp.

References createObject(), KStdAction::name(), and objectCreated().

void KLibFactory::objectCreated QObject obj  )  [signal]
 

Emitted in create.

Parameters:
obj the new object

Referenced by create().

QObject * KLibFactory::createObject QObject parent = 0,
const char *  name = 0,
const char *  classname = "QObject",
const QStringList args = QStringList()
[protected, pure 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

Implemented in KParts::Factory, KGenericFactory< Product, ParentType >, KGenericFactory< KTypeList< Product, ProductListTail >, QObject >, and KGenericFactory< KTypeList< Product, ProductListTail >, KTypeList< ParentType, ParentTypeListTail > >.

Definition at line 85 of file klibloader.cpp.

Referenced by create().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:49:37 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001