# class KLibLoader

###

Module | kdecore
Namespace |
Class | KLibLoader
Inherits | QObject

\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>

### enums

- ComponentLoadingError { ErrNoLibrary, ErrNoFactory, ErrNoComponent, ErrServiceProvidesNoLibrary, ErrNoServiceFound }

enum details

### methods

- KLibLoader ( )

  returns dtor
  Not implemented

- KLibLoader ( )

  returns ctor
  Not implemented

- errorString (componentLoadingError)

  returns QString
  static

  Argument | Type | Default
  --- | --- | ---
  componentLoadingError | int |

  Returns a translated error message for componentLoadingError

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

- factory (libname, loadHint)

  returns KPluginFactory

  Argument | Type | Default
  --- | --- | ---
  libname | QString |
  loadHint | QLibrary.LoadHints | 0

  Loads and initializes a library. Loading a library multiple times is handled gracefully.

  This is a convenience function that returns the factory immediately

  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

- findLibrary (libname, cData)

  returns QString
  static

  Argument | Type | Default
  --- | --- | ---
  libname | QString |
  cData | KComponentData | 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.

  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

- lastErrorMessage ( )

  returns QString

  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

- library (libname, loadHint)

  returns KLibrary

  Argument | Type | Default
  --- | --- | ---
  libname | QString |
  loadHint | QLibrary.LoadHints | 0

  Loads and initializes a library. Loading a library multiple times is handled gracefully.

  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

- self ( )

  returns KLibLoader
  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

- unloadLibrary (libname)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  libname | QString |

  Unloads the library with the given name.

  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.

### enums - detail

- ComponentLoadingError { ErrNoLibrary, ErrNoFactory, ErrNoComponent, ErrServiceProvidesNoLibrary, ErrNoServiceFound }

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

  | ErrNoLibrary | - 1 | - |
  | ErrNoFactory | - | - |
  | ErrNoComponent | - | - |
  | ErrServiceProvidesNoLibrary | - | - |
  | ErrNoServiceFound | - | - |