Hedge
Hedge

Reputation: 16768

How will users add extra functionality in QML based plugin system?

I've got a small application where users may create their own plugins as QML-files. These plugins get notification upon certain events and their user-interfaces are displayed one-by-one in a TabView.

Some plugins however need functionality which can't be provided via QML like writing to files. How would I enable my users to extend the functionality as they please?

Upvotes: 0

Views: 673

Answers (1)

JKSH
JKSH

Reputation: 2718

Your user must:

  1. Implement a QObject in C++ that provides the required functionality.
  2. Subclass QQmlExtensionPlugin to register that QObject as a QML type.
  3. Build a DLL (or SO or DYLIB) for #1 and #2, and write a qmldir file to tell the QML engine how to load the DLL.

EDIT: Qt Creator automates a bit of this process for you. Go to "File" -> "New File or Project..." -> "Projects" -> "Libraries" -> "Qt Quick 2 Extension Plugin"

You can find more details about this process in the documentation:

Note 1: Your user won't be writing a *.qml file.

Note 2: Each plugin must be in its own subfolder. This is because each C++ plugin needs one qmldir file, but you can't have multiple qmldir files in the same folder.

You can find some real examples in your Qt installation. Go to, say, C:\Qt\5.3\mingw482_32\qml -- all the subfolders here contain QML plugins, mostly written in C++. Here is some sample source code:

Upvotes: 1

Related Questions