KParts::PartLoader

KParts::PartLoader Namespace Reference

Functions

template<class T >
static T * createPartInstanceForMimeType (const QString &mimeType, QWidget *parentWidget=nullptr, QObject *parent=nullptr, QString *error=nullptr)
 
KPARTS_EXPORT QVector< KPluginMetaDatapartsForMimeType (const QString &mimeType)
 

Detailed Description

Helper methods for locating and loading parts.

This is based upon KPluginLoader and 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

template<class T >
static T* KParts::PartLoader::createPartInstanceForMimeType ( const QString mimeType,
QWidget parentWidget = nullptr,
QObject parent = nullptr,
QString error = nullptr 
)
static

Use this method to create a KParts part.

It will try to create an object which inherits T.

Example:

QString errorString;
m_part = KParts::PartLoader::createPartInstanceForMimeType<KParts::ReadOnlyPart>(
mimeType, this, this, &errorString);
if (m_part) {
layout->addWidget(m_part->widget()); // Integrate the widget
createGUI(m_part); // Integrate the actions
m_part->openUrl(url);
} else {
qWarning() << errorString;
}
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.
errorOptional output parameter, it will be set to the error string, if any.
Returns
A pointer to the created object is returned, or nullptr if an error occurred.
Since
5.69

Definition at line 85 of file partloader.h.

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

Locate all available KParts 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).

This uses KPluginLoader::findPlugins, i.e. it requires the parts to provide the metadata as JSON embedded into the plugin. Until KF6, however, it also supports .desktop files as a fallback solution.

To load a part from one of the KPluginMetaData instances returned here, simply do

KPluginLoader loader(metaData.fileName());
m_part = loader.factory()->create<KParts::ReadOnlyPart>(parentWidget, parent);
Since
5.69

Definition at line 78 of file partloader.cpp.

This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Sep 29 2020 23:01:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.