KParts::PartLoader Namespace Reference


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.


Function Documentation

◆ createPartInstanceForMimeType()

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

Use this method to create a KParts part.

It will try to create an object which inherits T.


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
} else {
qWarning() << errorString;
Template Parameters
TThe interface for which an object should be created. The object will inherit T.
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.
A pointer to the created object is returned, or nullptr if an error occurred.

Definition at line 88 of file partloader.h.

◆ partsForMimeType()

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

Locate all available KParts for a mimetype.

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 KPluginMetaData::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);

Definition at line 77 of file partloader.cpp.

Base class for any "viewer" part.
Definition: readonlypart.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Sep 27 2022 04:20:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.