4
votes

I have the following C++ model structure:

Manager             // QAbstractListModel
   ↪ Slot           // QAbstractListModel
       ↪ Processor  // QAbstractListModel
            ↪ name  // Q_PROPERTY

I pass only the Manager reference to QML on instantiation. I need to fill the ComboBox with Processor names but I don't know how to fill up with this nested structure.

Here is the code I plan to have (but is not working now):

ComboBox {
    model: Repeater {
        model: manager
        delegate: Repeater {
            model: slot
            delegate:Repeater {
                model: processor
                delegate: ListModel {
                    ListElement {text: name}
                }
            }
        }
    }
}

I know that delegates are for specifying how to display data (and that's why ComboBox doesn't have this one), but I'm out of ideas how to implement this correctly.

So my question is: how to fill up a ListModel recursively?

2
This question is still actual. Because of the down-vote I tried to simplify it greatly and I hope it is more clear now. - szotsaki

2 Answers

1
votes

I came up with the following solution to recursively fill a ComboBox:

ComboBox {
    id: comboBox
    model: ListModel {}
    textRole: "processorName"

    Repeater {
        model: manager
        delegate: Repeater {
            model: slot
            delegate: Repeater {
                model: processor
                Component.onCompleted: 
                    comboBox.model.append(
                        {"processorName": model.Processor.Name}
                    );
            }
        }
    }
}
0
votes

Add to your QAbstractListModel role that returns another QAbstractListModel.