Store QList<QObject*> as ListElement data in ListModel

  • I am using QList<QObject*> cppObjectList as a context property in my QML module.

    My ListElement form is as follows:

    ListElement {
          _childList: cppObjectList 

    Using ListModel's setProperty(<element_index>, "_childList", cppObjectList ) to set the cppObjectList to _childList

    Then I try printing the _childList (through model._childList) inside my ListView delegate, it just outputs undefined.
    So, anyone knows the reason why or just I cannot do that?

    By the way, I can totally do like this:

    Item {
          id: item
          property var _objectList
          function setObjectList() {
                   _objectList = cppObjectList; // cppObjectList is set as QQmlContext property as QVariant.

    then use item._objectList as model in my Listview, which is fine!

    So, it seems that cppObjectList can only be set directly to Item's property var and cannot be used as data inside a ListElement, doesn't it?

Log in to reply