KPluginLoader is not much more than a wrapper around QPluginLoader. The code itself suggests removing it eventually: https://invent.kde.org/frameworks/kcoreaddons/-/blob/master/src/lib/plugin/kpluginloader.cpp#L24
The main feature it provides is the pluginVersion method that extracts a version number that has been put into the binary via the K_EXPORT_PLUGIN_VERSION macro. Very few projects actually make proper use of the information though:
- Kontact sets the macro in https://invent.kde.org/pim/kontactinterface/-/blob/master/src/plugin.h#L67 but never reads the information
- Cantor sets the macro in https://invent.kde.org/education/cantor/-/blob/master/src/lib/cantor_macros.h#L33 but never reads the information
- Plasma uses it for applets, dataengines and runners and actually verifies that the major version matches (https://invent.kde.org/frameworks/plasma-framework/-/blob/master/src/plasma/version.cpp#L39)
- KWin uses it for both the effects API and the new binary plugin API and actually enforces it.
- Purpose sets the macro but never reads the information
For most use cases using QPluginLoader would therefore be sufficient. Removing the version handling as it is now would allow to get rid of the KPluginLoader class. What would stay around in some form are the various static methods for finding plugins.
For the cases where we still want to do version checking I see a few alternatives:
- Add the version information to the JSON metadata instead. This would allow to do the filtering earlier in the loading process and not require to load the plugin before discarding it again.
- Keep the version information in the binary and load it from a static function, something like
quint32 readVersion(const QString &fileName) { QLibrary lib(fileName); quint32 *version = reinterpret_cast<quint32 *>(lib.resolve("kde_plugin_version")); return *version; }
This requires the plugin to be loaded before calling it though.