UniDeskPluginInterface
Abstract base class that any C++ plugin must implement to be loaded by UniDeskPluginMgr. Any DLL plugin that wishes to be loaded must inherit this class and override its two pure virtual methods.
| Item | Description |
|---|---|
| Type | C++ abstract interface (not a QML type) |
| Source File | UniDesk/CppExt/UniDeskPluginInterface.h |
| IID | com.unidesk.plugin.PluginInterface |
Interface Definition
cpp
class UniDeskPluginInterface {
public:
virtual ~UniDeskPluginInterface() = default;
virtual void registerQmlTypes(QQmlApplicationEngine *engine) = 0;
virtual void initialize() = 0;
};Methods
virtual void registerQmlTypes(QQmlApplicationEngine *engine) = 0
Plugins register their C++ types, singletons, or QML file paths with the QML engine here. Typical usage:
cpp
void MyPlugin::registerQmlTypes(QQmlApplicationEngine *engine) {
qmlRegisterType<MyComponent>("MyPlugin", 1, 0, "MyComponent");
engine->addImportPath("qrc:/");
}virtual void initialize() = 0
Plugin initialization entry point. Called after registerQmlTypes for starting background threads, loading resources, initializing state, etc.
Implementation Steps
- Include
UniDeskPluginInterface.hin your plugin project - Inherit
UniDeskPluginInterfaceand override both methods - Declare the interface with
Q_DECLARE_INTERFACE - Declare the IID with
Q_PLUGIN_METADATAin the plugin source file
cpp
// MyPlugin.h
#include "UniDeskPluginInterface.h"
class MyPlugin : public QObject, public UniDeskPluginInterface {
Q_OBJECT
Q_PLUGIN_METADATA(IID "com.unidesk.plugin.PluginInterface")
Q_INTERFACES(UniDeskPluginInterface)
public:
void registerQmlTypes(QQmlApplicationEngine *engine) override;
void initialize() override;
};cpp
// MyPlugin.cpp
#include "MyPlugin.h"
void MyPlugin::registerQmlTypes(QQmlApplicationEngine *engine) {
qmlRegisterType<MyClock>("MyPlugin", 1, 0, "MyClock");
}
void MyPlugin::initialize() {
qDebug() << "MyPlugin initialized";
}Loading Mechanism
UniDeskPluginMgr.loadPlugins()scans all DLLs in theplugins/directory- Each DLL is loaded via
QPluginLoader qobject_cast<UniDeskPluginInterface*>checks whether the interface is implemented- For valid plugins,
registerQmlTypes(engine)andinitialize()are called in order
Related
- UniDeskPluginMgr — Plugin manager
- Plugin Development Guide — Full plugin authoring workflow
- Official Plugins — Official plugin pack

