This is my situation:
I have class A with property which is the list of objects of class B. Here it is:
class A : public QObject {
Q_OBJECT
Q_PROPERTY(QQmlListProperty<B> bList READ bLIst NOTIFY bListChanged)
...
}
class B : public QObject {
Q_OBJECT
Q_PROPERTY(QVariant firstProperty READ firstProperty CONSTANT)
Q_PROPERTY(int secondProperty READ secondProperty CONSTANT)
...
}
In QML file i have a ListView. The A::bList is used as a model to this ListView.
ListView {
id: bListView
delegate: Text {
text: secondProperty
}
}
I initialise ListView from JS as:
Component.onCompleted: {
...
bListView.model = a.bList;
...
}
And this code works ok!
But my problem take place if i have some objects of class A and have to get single list with B objects.
I’m tring to do it with JS Arrays:
Component.onCompleted: {
...
var generalBList = new Array;
for (var i = 0; i < aList.length; ++i) {
var bList = aList[i].bList;
for (var j = 0; j < bList.length; ++j) {
generalBList.push(bList[j]);
}
}
bListView.model = generalBList;
...
}
ListView finds right count of elements, but can’t to get value of any property with error:
ReferenceError: secondProperty is not defined
Can I do my task only with QML and JS or i have to make general B list at C++ side?
↧