KParts::PartLoader

KParts::PartLoader Namespace Reference

Functions

template<typename T >
static KPluginFactory::Result< T > instantiatePart (const KPluginMetaData &data, QWidget *parentWidget=nullptr, QObject *parent=nullptr, const QVariantList &args={})
 
template<class T >
static KPluginFactory::Result< T > instantiatePartForMimeType (const QString &mimeType, QWidget *parentWidget=nullptr, QObject *parent=nullptr, const QVariantList &args={})
 
KPARTS_EXPORT QList< KPluginMetaDatapartsForMimeType (const QString &mimeType)
 

Detailed Description

Helper methods for locating and loading parts.

This is based upon KPluginFactory, but it takes care of querying by mimetype, sorting the available parts by builtin preference and by user preference.

Since
5.69

Function Documentation

◆ instantiatePart()

template<typename T >
static KPluginFactory::Result< T > KParts::PartLoader::instantiatePart ( const KPluginMetaData & data,
QWidget * parentWidget = nullptr,
QObject * parent = nullptr,
const QVariantList & args = {} )
static

Attempts to create a KPart from the given metadata.

if (auto result = KParts::PartLoader::instantiatePart<MyPart>(metaData, parentWidget, parent, args)) {
// result.plugin is valid and can be accessed
} else {
// result contains information about the error
}
static KPluginFactory::Result< T > instantiatePart(const KPluginMetaData &data, QWidget *parentWidget=nullptr, QObject *parent=nullptr, const QVariantList &args={})
Attempts to create a KPart from the given metadata.
Definition partloader.h:79
Parameters
dataKPluginMetaData from which the plugin should be loaded
parentWidgetThe parent widget
parentThe parent object
argsA list of arguments to be passed to the part
Returns
Result object which contains the plugin instance and potentially error information
Since
5.100

Definition at line 79 of file partloader.h.

◆ instantiatePartForMimeType()

template<class T >
static KPluginFactory::Result< T > KParts::PartLoader::instantiatePartForMimeType ( const QString & mimeType,
QWidget * parentWidget = nullptr,
QObject * parent = nullptr,
const QVariantList & args = {} )
static

Use this method to create a KParts part.

It will try to create an object which inherits T.

if (auto result = KParts::PartLoader::instantiatePartForMimeType<KParts::ReadOnlyPart>(mimeType, parentWidget, parent, args)) {
// result.plugin is valid and can be accessed
} else {
// result contains information about the error
}
Template Parameters
TThe interface for which an object should be created. The object will inherit T.
Parameters
mimeTypeThe mimetype for which we need a KParts.
parentWidgetThe parent widget for the part's widget.
parentThe parent of the part.
Returns
Result object which contains the plugin instance and potentially error information
Since
5.100

Definition at line 120 of file partloader.h.

◆ partsForMimeType()

QList< KPluginMetaData > KParts::PartLoader::partsForMimeType ( const QString & mimeType)

Locate all available KParts using KPluginMetaData::findPlugins for a mimetype.

Returns
a list of plugin metadata, sorted by preference. This takes care both of the builtin preference (set by developers) and of user preference (stored in mimeapps.list).

To load a part from one of the KPluginMetaData instances returned here, use instantiatePart()

Since
5.69

Definition at line 55 of file partloader.cpp.

This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:15:54 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.