KDE 5.0 PyKDE API Reference
  • KDE's Python API
  • Overview
  • PyKDE Home
  • Sitemap
  • Contact Us
 

KPluginLoader Class Reference

from PyKDE5.kcoreaddons import *

Inherits: QObject

Detailed Description

\class KPluginLoader kpluginloader.h <KPluginLoader>

This class behaves largely like QPluginLoader (and, indeed, uses it internally), but additionally reads the plugin version, as provided by the K_EXPORT_PLUGIN_VERSION macro (see pluginVersion()) and provides access to a KPluginFactory instance if the plugin provides one (see factory())

Note that the factory() is a typesafe convenience method that just wraps a qobject_cast on the result of QPluginLoader.instance(). Therefore, if you do not need the plugin version feature, you can (and should) just use QPluginLoader instead.

Unlike QPluginLoader, it is not possible to re-use KPluginLoader for more than one plugin (it provides no setFileName method).

The same notes and caveats that apply to QPluginLoader also apply to KPluginLoader.

Sample code:

  KPluginLoader loader( ...library or kservice... );
  KPluginFactory* factory = loader.factory();
  if (!factory) {
      kWarning() << "Error loading plugin:" << loader.errorString();
  } else {
      MyInterface* obj = factory->create<MyInterface>();
      if (!obj) {
          kWarning() << "Error creating object";
      }
  }

See also:
KPluginFactory

Author:
Bernhard Loos <nhuh.put@web.de>


Methods

 __init__ (self, QString plugin, QObject parent=0)
 __init__ (self, KPluginName name, QObject parent=0)
QString errorString (self)
KPluginFactory factory (self)
QString fileName (self)
QObject instance (self)
bool isLoaded (self)
bool load (self)
QLibrary::LoadHints loadHints (self)
QString pluginName (self)
long pluginVersion (self)
 setLoadHints (self, QLibrary::LoadHints loadHints)
bool unload (self)

Static Methods

QString findPlugin (QString name)

Method Documentation

__init__ (  self,
QString  plugin,
QObject  parent=0
)

Load a plugin by name.

This should be the name of the plugin object file, without any suffix (like .so or .dll). Plugin object files should not have a 'lib' prefix.

fileName() will be empty if the plugin could not be found.

Parameters:
plugin  The name of the plugin.

Parameters:
parent  A parent object.

__init__ (  self,
KPluginName  name,
QObject  parent=0
)

Load a plugin by name.

This constructor behaves exactly the same as KPluginLoader(const QString&,QObject*). It allows any class that can be cast to KPluginName (such as KService) to be passed to KPluginLoader.

Parameters:
name  The name of the plugin.

Parameters:
parent  A parent object.

QString errorString (   self )

Returns the last error.

Returns:
The description of the last error.

See also:
QPluginLoader.errorString()

KPluginFactory factory (   self )

Returns the factory object of the plugin.

This is typically created by one of the KPluginFactory macros. Internally, this uses QPluginLoader.instance(), and the same behaviours apply.

Returns:
The factory of the plugin or 0 on error.

QString fileName (   self )

Returns the path of the plugin.

This will be the full path of the plugin if it was found, and empty if it could not be found.

Returns:
The full path of the plugin, or the null string if it could not be found.

See also:
QPluginLoader.fileName(), pluginName()

QObject instance (   self )

Returns the root object of the plugin.

The plugin will be loaded if necessary. If the plugin used one of the KPluginFactory macros, you should use factory() instead.

Returns:
The plugin's root object.

See also:
QPluginLoader.instance()

bool isLoaded (   self )

Determines whether the plugin is loaded.

Returns:
True if the plugin is loaded, false otherwise.

See also:
QPluginLoader.isLoaded()

bool load (   self )

Loads the plugin.

It is safe to call this multiple times; if the plugin was already loaded, it will just return true.

Methods that require the plugin to be loaded will load it as necessary anyway, so you do not normally need to call this method.

Returns:
True if the plugin was loaded successfully, false otherwise.

See also:
QPluginLoader.load()

QLibrary::LoadHints loadHints (   self )

Returns the load hints for the plugin.

Determines how load() should work. See QLibrary.loadHints for more information.

Returns:
The load hints for the plugin.

See also:
QPluginLoader.loadHints(), setLoadHints()

QString pluginName (   self )

Returns the name of this plugin as given to the constructor.

If the KService constructor was used, this is the name of the library provided by the service.

Returns:
The plugin name.

See also:
fileName()

long pluginVersion (   self )

Returns the plugin version.

This will load the plugin if it is not already loaded.

Returns:
The version given to K_EXPORT_PLUGIN_VERSION, or (quint32) -1 if the macro was not used or the plugin could not be loaded.

setLoadHints (  self,
QLibrary::LoadHints  loadHints
)

Set the load hints for the plugin.

Determines how load() should work. See QLibrary.loadHints for more information.

Parameters:
loadHints  The load hints for the plugin.

See also:
QPluginLoader.setLoadHints(), loadHints()

bool unload (   self )

Attempts to unload the plugin.

If other instances of KPluginLoader or QPluginLoader are using the same plugin, this will fail; unloading will only happen when every instance has called unload().

Returns:
True if the plugin was unloaded, false otherwise.

See also:
QPluginLoader.unload(), load(), instance(), factory()


Static Method Documentation

QString findPlugin ( QString  name
)

Locates a plugin.

Searches for a dynamic object file in the locations KPluginLoader and QPluginLoader would search (ie: the current directory and QCoreApplication.libraryPaths()).

This can be useful if you wish to use a plugin that does not conform to the Qt plugin scheme of providing a QObject that declares Q_PLUGIN_METADATA. In this case, you can find the plugin with this method, and load it with QLibrary.

Note that the path is not necessarily absolute. In particular, if the plugin is found in the current directory, it will be a relative path.

Parameters:
name  The name of the plugin (can be a relative path; see above). This should not include a file extension (like .so or .dll).

Returns:
The path to the plugin if it was found, or QString() if it could not be found.

Since:
5.0

  • Full Index

Modules

  • karchive
  • kcoreaddons
  • kguiaddons
  • kitemmodels
  • kitemviews
  • kplotting
  • kwidgetsaddons
  • solid
  • sonnet
This documentation is maintained by Simon Edwards.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal