KDE 4.7 PyKDE API Reference

- KDE's Python API

# KLibLoader Class Reference

`from PyKDE4.kdecore import *`

Inherits: QObject

## Detailed Description

\class KLibLoader klibloader.h <KLibLoader>

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

See also:
  KPluginLoader

Author:
  Torben Weis <weis@kde.org>

## Enumerations
ComponentLoadingError | { ErrNoLibrary, ErrNoFactory, ErrNoComponent, ErrServiceProvidesNoLibrary, ErrNoServiceFound }
## Methods
| __init__ (self)
KPluginFactory | factory (self, QString libname, QLibrary::LoadHints loadHint=0)
QString | lastErrorMessage (self)
KLibrary | library (self, QString libname, QLibrary::LoadHints loadHint=0)
| unloadLibrary (self, QString libname)
## Static Methods
QString | errorString (int componentLoadingError)
QString | findLibrary (QString libname, KComponentData cData=KGlobal.mainComponent())
KLibLoader | self ()

## Method Documentation

__init__ | ( |  | self ) |

KPluginFactory factory | ( | self, |
|  | 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.

Parameters:

  | loadHint | provides more control over how the library is loaded

Returns:
  the KPluginFactory, or 0 if the library does not exist or it does not have a factory

See also:
  library

QString lastErrorMessage | ( |  | self ) |

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

KLibrary library | ( | self, |
|  | 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.

Parameters:

  | loadHint | provides more control over how the library is loaded

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

unloadLibrary | ( | self, |
|  | 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.

## Static Method Documentation

QString errorString | ( | int | componentLoadingError
| ) |  |  |

Converts a numerical error code into a human-readable error message

Parameters:

  | componentLoadingError | the error code, as set using the error parameter of createInstance()

Returns:
  the translated error message describing the error represented by componentLoadingError

See also:
  ComponentLoadingError

QString findLibrary | ( | QString | libname,
|  | KComponentData | cData=KGlobal.mainComponent()
| ) |  |  |

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

Returns:
  the name of the library if it was found, an empty string otherwise

KLibLoader self | ( |  | ) |

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 instead

## Enumeration Documentation

ComponentLoadingError

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

Use errorString() to convert the error code to a human-readable string

Enumerator:

  ErrNoLibrary = 1 |
  ErrNoFactory |
  ErrNoComponent |
  ErrServiceProvidesNoLibrary |
  ErrNoServiceFound |