[Interest] QQmlPropertyList x QList in hybrid C++/QML APIs

Sandro Andrade sandroandrade at kde.org
Fri Jun 14 18:15:28 CEST 2013


Hi there,

I've a bunch of classes which define a number of Q_PROPERTies with
type QList<some-QObject-based-class *>. Those classes are inspected by
a generic widgets-based property editor which uses QMetaProperty
functions to handle item's properties.

E.g:

class Q_UML_EXPORT QUmlClass : public QWrappedObject
{
    Q_OBJECT
    Q_CLASSINFO("MetaModelPrefix", "QUml")
...
    Q_PROPERTY(QList<QUmlOperation *> ownedOperations READ ownedOperations)
    Q_PROPERTY(QList<QUmlProperty *> ownedAttributes READ ownedAttributes)
...

Now, I need to use QML to provide some visual representation of those
same elements and, therefore, QML objects should be dynamically
created based on QList-based properties' contents:

import QtQuick 2.0

Rectangle {
...
    UmlSlot {
        id: nameSlot
    }
    UmlSlot {
        id: propertiesSlot
        anchors.top: nameSlot.bottom
        anchors.topMargin: -1
        height: nameSlot.height; width: nameSlot.width
    }
...
    Component.onCompleted: {
        if (element) {
            var visibility;
            switch (element.visibility) {
                case 0: visibility = "+"; break;
                case 1: visibility = "-"; break;
                case 2: visibility = "#"; break;
                case 3: visibility = "~"; break;
            }
            name = visibility + element.objectName;
            nameSlot.labelFont.italic = element.isAbstract; // Works
fine so far ...
            element.ownedAttributes <- here I got an undefined object
        }
    }
}

Qt5 docs say that such properties should be declared as
QQmlListProperty, but I'm wondering if I have to maintain two
different classes/properties in order to have this working. I haven't
used qmlRegisterType() so far, it seems QObject-based type are
automatically registered in QML as metatype registration do in Qt5.

So, any hints on how to have such QML/C++ things living together ?

Thanks in advance,
--
Sandro



More information about the Interest mailing list