QML property list empty when accessed from C++



  • Good afternoon,

    How can a qml property list be accessed from C++ side?

    I think an example should make things clear:
    @
    // MyItem.qml
    Rectangle
    {
    // some properties
    }

    // MyComponent.qml,
    CppComponent // available through qmlRegisterType<CMyComponent>("myComponents", 1, 0, "CppComponent");
    {
    width: 100
    height: 62

    property list<MyItem> myItems;
    

    }
    @

    @
    // Usage.qml
    Rectangle
    {
    width: 100
    height: 62

    MyComponent
    {
        myItems: // <--- the property list gets filled here
        [
            MyItem
            {
                x: 100
                y: interpolator.rotationCenter.y
                width: 150
                height: 200
            },
    
            MyItem
            {
                x: 100
                y: interpolator.rotationCenter.y
                width: 150
                height: 200
            }
        ]
    }
    

    }
    @

    The big question is: how can the property list be accessed from C++
    side?

    My stupid approach was:
    @
    QQmlListProperty<QQuickItem> mis = this->property("maskItems").value<QQmlListProperty<QQuickItem> >();
    @

    because
    @
    this->property("maskItems").typeName();
    @

    returns "QQmlListProperty<MyItem_QMLTYPE_0>"

    But the list is empty...

    I also tried a QList<QQuickItem *>, QVariantList and some other stupid things
    I cannot remember anymore but it's the same all the time:
    no items are contained in the list when it is accessed from C++ side

    What's wrong here?

    Thank you in advance,
    Martin


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.