Plasmoid with C++ plugin – correct .so/qmldir location?

I’m trying to make a plasmoid for KDE/Plasma 6, which needs to access a network service, so, as I understand, it can’t be made with qml alone and requires C++ QML plugin.

I created a plugin that successfully builds with qt_add_qml_module cmake directive and is installed with:

qt_query_qml_module(my_sensor_plugin
  QMLDIR plugin_qmldir
  TYPEINFO plugin_typeinfo
  TARGET_PATH plugin_targetpath
)

install(TARGETS my_sensor_plugin DESTINATION ${KDE_INSTALL_QMLDIR}/${plugin_targetpath})

install(FILES "${plugin_qmldir}"   DESTINATION ${KDE_INSTALL_QMLDIR}/${plugin_targetpath})
install(FILES "${plugin_typeinfo}" DESTINATION ${KDE_INSTALL_QMLDIR}/${plugin_targetpath})

And it ends up in ~/.local/lib/qt6/qml/my_sensor/widget/dataprovider (when I install it with ~/.local install prefix for testing). This directory contains my_sensor_plugin.so, qmldir and my_sensor_plugin.qmltypes.

When qml code tries to import it, plasmawindowed shows this error:

file:///home/example/.local/share/plasma/plasmoids/my_sensor.widget/contents/ui/main.qml:5:1: module “my_sensor.widget.dataprovider” is not installed

When running plasmawindowed under strace I don’t see it trying to access anything in ~/.local/lib/qt6 at all, so it seems that it’s not a problem within plugin’s .so library or qmldir: these files aren’t even accessed.

What is the correct path to install QML C++ plugin/extension for Plasma widget?

For the C++ plugin to work in my third-party add-ons when installed in ~/.local/ I had to add the QML_IMPORT_PATH environment variable

QML_IMPORT_PATH="$HOME/.local/lib64/qml:$HOME/.local/lib/qml:$QML_IMPORT_PATH"

I added it to $HOME/.config/plasma-workspace/env/path.sh

Initially had only lib but some distributions like fedora install the plugin in lib64

2 Likes

Thank you, it worked!

Regarding strace, I missed tracing of many system calls including opening of files due to plasmawindowed using subprocesses so strace should’ve been called with -f.


Additionally, I had to use add_library in addition to qt_add_qml_module, otherwise shared object file hasn’t had lib filename prefix.

My working CMakeLists.txt is:
add_library(MySensorDataProvider SHARED
  MySensorRequester.cpp
)

qt_add_qml_module(MySensorDataProvider
  URI "my_sensor.widget.dataprovider"
  PLUGIN_TARGET MySensorDataProvider
)

qt_query_qml_module(MySensorDataProvider
  QMLDIR plugin_qmldir
  TYPEINFO plugin_typeinfo
  TARGET_PATH plugin_targetpath
)

install(TARGETS MySensorDataProvider DESTINATION ${KDE_INSTALL_QMLDIR}/${plugin_targetpath})
install(FILES "${plugin_qmldir}"   DESTINATION ${KDE_INSTALL_QMLDIR}/${plugin_targetpath})
install(FILES "${plugin_typeinfo}" DESTINATION ${KDE_INSTALL_QMLDIR}/${plugin_targetpath})