[Interest] (Q)Plugins and QML/Quick

Konstantin Shegunov kshegunov at gmail.com
Tue Sep 14 23:24:59 CEST 2021

On Tue, Sep 14, 2021 at 9:02 PM Rui Oliveira <ruilvo at hotmail.com> wrote:

> PS: For reference, I'm talking about what would be the QML/Quick
> equivalent of the Plug and Paint example:
> https://doc-snapshots.qt.io/qt6-dev/qtwidgets-tools-plugandpaint-app-example.html
> Where the plugins bring UI components with themselves.

Off the top of my head, if I were to do something akin, I'd push the
"container" quick item (e.g. the menu item in the 'plug and paint') through
the plugin interface, in which (plugin) I'd instantiate a QComponent and
then create the actual QQuickItem from it (QComponent::createObject). As
soon as the interactions get complicated this may be rather tedious and/or
error-prone though. You could attach "stuff" (e.g. signals and such) in the
plugin instantiated component (a.k.a. UI file) given that the correct
context's been provided. The actual plugin(s) you can expose through a
QObject adapter that bridges the QML world to the QPlugin/interfaces world.
I haven't tried it as such, but should work in theory.

Alternatively, it may be possible for you to derive from QQuickItem just
for the purpose of providing a QML context for runtime created items and
load your plugins/cast their interfaces, instantiate components/quick items
there; then expose the QQuickItem objects as  a property (or something),
possibly reparent them to your type's parent or even do the creation
directly with the correct parent.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210915/24af1b40/attachment.html>

More information about the Interest mailing list