3
votes

I have a hierarchical (nested) QAbstractListModel in C++, i.e. the items of an Outer model are instances of an Inner model and the items of class Inner are some QObject derived Data instances. Outer has a submodel role for access to Inner items.

The corresponding QML code nests a Repeater inside a ListView. The ListView properly iterates items of type Inner and I can retrieve the item count of Inner model instances in the ListView delegate.
The problem I have is that the Repeater just does not iterate over the Data instances of an Inner model. Using debug printouts in methods of the C++ model I see that

  • QML queries the rowCount() of instances of Inner but
  • QML does never call data() on instances of Inner.

The QML code looks like this:

import QtQuick 2.0
import QtQuick.Controls 1.3
import NestedModels 1.0  as Models

ScrollView {
    width: 1980; height:600
    Component {
        id: inner
        Item {
            Text {
                x:1000;	font.pointSize: 9
                text: "inner " + model.name
            }
        }
    }

    Component {
        id: outer
        Item {
            height: 40
            property var innerModel: model.submodel
            Text {
                font.pointSize: 9
                text: "outer " + model.objectName
                + ": inner " +  innerModel
            }

            Repeater {
                model: innerModel
                delegate: inner
            }
        }
    }

    ListView {
         Models.OuterModel { id: outerModel }
         model: outerModel
         delegate: outer
         Text {
             x: 200; y: 400;	font.pointSize: 9
             text: outerModel.objectName + ": " + outerModel.count + " rows. " + outerModel.getItem(0)
         }
     }
 }
1

1 Answers

1
votes

Try to use separate qml file OuterDelegate.qml I had the same issue, the problem is that you passing inner model to repeater incorrectly