KParts::PartLoader Namespace
namespace KParts::PartLoaderHelper methods for locating and loading parts. More...
Header: | #include <KParts/PartLoader> |
CMake: | find_package(KF6 REQUIRED COMPONENTS Parts) target_link_libraries(mytarget PRIVATE KF6::Parts) |
Since: | KParts 5.69 |
Functions
(since 5.100) KPluginFactory::Result<T> | instantiatePart(const KPluginMetaData &data, QWidget *parentWidget = nullptr, QObject *parent = nullptr, const QVariantList &args = {}) |
(since 5.100) KPluginFactory::Result<T> | instantiatePartForMimeType(const QString &mimeType, QWidget *parentWidget = nullptr, QObject *parent = nullptr, const QVariantList &args = {}) |
(since KParts 6.4) KParts::PartCapabilities | partCapabilities(const KPluginMetaData &data) |
(since 5.69) QList<KPluginMetaData> | partsForMimeType(const QString &mimeType) |
Detailed Description
This is based upon KPluginFactory, but it takes care of querying by mimetype, sorting the available parts by builtin preference and by user preference.
Function Documentation
[since 5.100]
template <typename T> KPluginFactory::Result<T> PartLoader::instantiatePart(const KPluginMetaData &data, QWidget *parentWidget = nullptr, QObject *parent = nullptr, const QVariantList &args = {})
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 }
data KPluginMetaData from which the plugin should be loaded
parentWidget The parent widget
parent The parent object
args A list of arguments to be passed to the part
Returns a Result object which contains the plugin instance and potentially error information
This function was introduced in 5.100.
[since 5.100]
template <typename T> KPluginFactory::Result<T> PartLoader::instantiatePartForMimeType(const QString &mimeType, QWidget *parentWidget = nullptr, QObject *parent = nullptr, const QVariantList &args = {})
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 }
T The interface for which an object should be created. The object will inherit T.
mimeType The mimetype for which we need a KParts.
parentWidget The parent widget for the part's widget.
parent The parent of the part.
Returns a Result object which contains the plugin instance and potentially error information
This function was introduced in 5.100.
[since KParts 6.4]
KParts::PartCapabilities PartLoader::partCapabilities(const KPluginMetaData &data)
Parses the associated capabilities from the KPart. This parses the deprecated "ServiceTypes" array of the "KPlugin" object
This function was introduced in KParts 6.4.
[since 5.69]
QList<KPluginMetaData> 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()
This function was introduced in 5.69.