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

KDECore

KLibLoader Class Reference

#include <KLibLoader>

Inheritance diagram for KLibLoader:

Inheritance graph
[legend]

List of all members.


Detailed Description

The KLibLoader allows you to load libraries dynamically at runtime.

Dependent libraries are loaded automatically.

KLibLoader follows the singleton pattern. You can not create multiple instances. Use self() to get a pointer to the loader.

Deprecated:
You have two other possibilites: KPluginLoader or KService::createInstance for plugins KLibrary for other libraries
See also:
KLibrary

KPluginLoader

Author:
Torben Weis <weis@kde.org>

Definition at line 53 of file klibloader.h.


Public Types

enum  ComponentLoadingError {
  ErrNoLibrary = 1, ErrNoFactory, ErrNoComponent, ErrServiceProvidesNoLibrary,
  ErrNoServiceFound
}

Public Member Functions

KPluginFactory * factory (const QString &libname, QLibrary::LoadHints loadHint=0)
QString lastErrorMessage () const
KLibrary * library (const QString &libname, QLibrary::LoadHints loadHint=0)
void unloadLibrary (const QString &libname)

Static Public Member Functions

template<typename T>
static T * createInstance (const QString &libname, QObject *parent, const QStringList &args, int *error=0)
template<typename T>
static T * createInstance (const QString &libname, QObject *parent=0, const QVariantList &args=QVariantList(), int *error=0)
template<typename T>
static T * createInstance (const QString &keyword, const QString &libname, QObject *parent=0, const QVariantList &args=QVariantList(), int *error=0)
static QString errorString (int componentLoadingError)
static QString findLibrary (const QString &libname, const KComponentData &cData=KGlobal::mainComponent())
static KLibLoader * self ()

Member Enumeration Documentation

enum KLibLoader::ComponentLoadingError

This enum type defines the possible error cases that can happen when loading a component.

  • ErrNoLibrary - the specified library could not be loaded. Use KLibLoader::lastErrorMessage for details.
  • ErrNoFactory - the library does not export a factory for creating components
  • ErrNoComponent - the factory does not support creating components of the specified type
  • ErrServiceProvidesNoLibrary - the specified service provides no shared library (when using KService)
  • ErrNoServiceFound - no service implementing the given servicetype and fullfilling the given constraint expression can be found (when using KServiceTypeTrader).
Enumerator:
ErrNoLibrary 
ErrNoFactory 
ErrNoComponent 
ErrServiceProvidesNoLibrary 
ErrNoServiceFound 

Definition at line 170 of file klibloader.h.


Member Function Documentation

template<typename T>
static T* KLibLoader::createInstance ( const QString &  libname,
QObject *  parent,
const QStringList &  args,
int *  error = 0 
) [inline, static]

Deprecated:
Use one of the other createInstance methods or KPluginLoader or KService::createInstance instead

Definition at line 241 of file klibloader.h.

template<typename T>
static T* KLibLoader::createInstance ( const QString &  libname,
QObject *  parent = 0,
const QVariantList &  args = QVariantList(),
int *  error = 0 
) [inline, static]

Definition at line 229 of file klibloader.h.

template<typename T>
static T* KLibLoader::createInstance ( const QString &  keyword,
const QString &  libname,
QObject *  parent = 0,
const QVariantList &  args = QVariantList(),
int *  error = 0 
) [inline, static]

This template allows to load the specified library and ask the factory to create an instance of the given template type.

Parameters:
libraryName The library to open
parent The parent object (see QObject constructor)
args A list of string arguments, passed to the factory and possibly to the component (see KPluginFactory)
error 
Returns:
A pointer to the newly created object or a null pointer if the factory was unable to create an object of the given type.

Definition at line 197 of file klibloader.h.

QString KLibLoader::errorString ( int  componentLoadingError  )  [static]

Returns a translated error message for componentLoadingError.

Parameters:
componentLoadingError the error code, as returned in the "error" output parameter of createInstance.

Definition at line 142 of file klibloader.cpp.

KPluginFactory * KLibLoader::factory ( const QString &  libname,
QLibrary::LoadHints  loadHint = 0 
)

Loads and initializes a library.

Loading a library multiple times is handled gracefully.

This is a convenience function that returns the factory immediately

Parameters:
libname This is the library name without extension. Usually that is something like "libkspread". The function will then search for a file named "libkspread.la" in the KDE library paths. The *.la files are created by libtool and contain important information especially about the libraries dependencies on other shared libs. Loading a "libfoo.so" could not solve the dependencies problem.
You can, however, give a library name ending in ".so" (or whatever is used on your platform), and the library will be loaded without resolving dependencies. Use with caution.
Returns:
the KPluginFactory, or 0 if the library does not exist or it does not have a factory
See also:
library

Definition at line 127 of file klibloader.cpp.

QString KLibLoader::findLibrary ( const QString &  libname,
const KComponentData &  cData = KGlobal::mainComponent() 
) [static]

Helper method which looks for a library in the standard paths ("module" and "lib" resources).

Made public for code that doesn't use KLibLoader itself, but still wants to open modules.

Parameters:
libname of the library. If it is not a path, the function searches in the "module" and "lib" resources. If there is no extension, ".la" will be appended.
cData a KComponentData used to get the standard paths

Definition at line 84 of file klibloader.cpp.

QString KLibLoader::lastErrorMessage (  )  const

Returns an error message that can be useful to debug the problem.

Returns QString() if the last call to library() was successful. You can call this function more than once. The error message is only reset by a new call to library().

Returns:
the last error message, or QString() if there was no error

Definition at line 118 of file klibloader.cpp.

KLibrary * KLibLoader::library ( const QString &  libname,
QLibrary::LoadHints  loadHint = 0 
)

Loads and initializes a library.

Loading a library multiple times is handled gracefully.

Parameters:
libname This is the library name without extension. Usually that is something like "libkspread". The function will then search for a file named "libkspread.la" in the KDE library paths. The *.la files are created by libtool and contain important information especially about the libraries dependencies on other shared libs. Loading a "libfoo.so" could not solve the dependencies problem.
You can, however, give a library name ending in ".so" (or whatever is used on your platform), and the library will be loaded without resolving dependencies. Use with caution.
Returns:
KLibrary is invalid (0) when the library couldn't be dlopened. in such a case you can retrieve the error message by calling KLibLoader::lastErrorMessage()
See also:
factory

Definition at line 89 of file klibloader.cpp.

KLibLoader * KLibLoader::self (  )  [static]

Returns a pointer to the factory.

Use this function to get an instance of KLibLoader.

Returns:
a pointer to the loader. If no loader exists until now then one is created.
Deprecated:
use KPluginLoader

Definition at line 46 of file klibloader.cpp.

void KLibLoader::unloadLibrary ( const QString &  libname  ) 

Unloads the library with the given name.

Parameters:
libname This is the library name without extension. Usually that is something like "libkspread". The function will then search for a file named "libkspread.la" in the KDE library paths. The *.la files are created by libtool and contain important information especially about the libraries dependencies on other shared libs. Loading a "libfoo.so" could not solve the dependencies problem.
You can, however, give a library name ending in ".so" (or whatever is used on your platform), and the library will be loaded without resolving dependencies. Use with caution.

Definition at line 123 of file klibloader.cpp.


The documentation for this class was generated from the following files:
  • klibloader.h
  • klibloader.cpp

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal