class KLibFactory

If you develop a library that is to be loaded dynamically at runtime, then you should provide a function that returns a pointer to your factory like this: More...

Definition#include <klibloader.h>
InheritsQObject (qt) [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Signals

Protected Methods


Detailed Description

If you develop a library that is to be loaded dynamically at runtime, then you should provide a function that returns a pointer to your factory like this:


 extern "C"
 {
   void* init_libkspread()
   {
     return new KSpreadFactory;
   }
 };

You should especially see that the function must follow the naming pattern "init_libname".

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


     s_global = new KInstance( "kspread" );

This KInstance is compareable to KGlobal used by normal applications. It allows you to find ressource 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.

 KLibFactory ( QObject* parent = 0, const char* name = 0 )

KLibFactory

Create a new factory.

 ~KLibFactory ()

~KLibFactory

[virtual]

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

create

[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.

Never reimplement this function. Instead, reimplement createObject().

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.

This function is virtual for compatibility reasons only.

void  objectCreated ( QObject *obj )

objectCreated

[signal]

Emitted in create

QObject*  createObject ( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() )

createObject

[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()