How to correctly load/install app plugins in kf5 5.90+?


So I’m trying to port my app to new KF5 (and eventually KF6), but I ran into a problem with plug-ins. I’ve been using KPluginInfo::fromServices and KServiceTypeTrader::self()->query to locate plugins and KPluginLoader to load them, but apparently most of that is deprecated since 5.90 and plugins are not included in the service trader database at all now, as far as I can tell.

Also, I’m installing plugins into KDE_INSTALL_PLUGINDIR and the associated .desktop file to KDE_INSTALL_KSERVICES5DIR, but it looks like the new-style methods want a per-app directory and it’s unclear whether the .desktop files should exist at all.

I can find some progress discussions and API docs, but nothing that would provide any kind of a high-level overview on how to install and load plugins using the new approach. Is there any documentation / design doc / anything like that out there?

Thank you!

I don’t think there’s a comprehensive overview. The gist is

  • Use JSON metadata embedded into the plugin binary (i.e. use K_PLUGIN_CLASS_WITH_JSON)
  • Install the plugins into a subfolder for the specific type
  • Use KPluginMetaData to query available plugins
  • Use KPluginFactory::instantiatePlugin to load a plugin
1 Like

Okay, I’ll give it a try, thank you!