QQMLListProperty & append function
-
Trying to use the QQMListProperty along with append function. Sample code is here
return QQmlListProperty<User>(this, 0, &UserList::append_user, 0, 0, 0);
I'm trying find out when does the append_user function called ? I tried all my ways to see if append_user function is called. Not successful.
What I'm looking for -
Readymade sample example to show how append_function is called. -
Hi @dheerendra
I think that your function should be called everytime your adding a QML user object on your .qml file :
for example if you add :
user{ }, user{ }
on your .qml file ,
append _function
should be called two times .You can see this example from qt doc:
http://doc.qt.io/qt-5/qtqml-tutorials-extending-qml-example.html#chapter-5-using-list-property-types
You can use this example on your Qt creator , and add :
qDebug() << Q_FUNC_INFO;
on PIECHART.cpp file , in append_slice function
then cause in qml file we are using 3 slice qml object like this :
slices: [ PieSlice { anchors.fill: parent color: "red" fromAngle: 0; angleSpan: 110 }, PieSlice { anchors.fill: parent color: "black" fromAngle: 110; angleSpan: 50 }, PieSlice { anchors.fill: parent color: "blue" fromAngle: 160; angleSpan: 100 } ]
you will see that append_slice function is called 3times, you can even add more qml object and see the change.
Console log:
QML debugging is enabled. Only use this in a safe environment. static void PieChart::append_slice(QQmlListProperty<PieSlice>*, PieSlice*) static void PieChart::append_slice(QQmlListProperty<PieSlice>*, PieSlice*) static void PieChart::append_slice(QQmlListProperty<PieSlice>*, PieSlice*)
Hope this can help.
-
cool. Thank you for your answer. While creating the list, it is called. My thinking was that, after creating the list, is there way to append to the list so that append_function is called.
-
@dheerendra
I am not sure I fully understand what do you mean,do you wanna add an element to your list without adding it to your qml file?
Could you tell us more about what you really wanna do ?
Thank you
-
@mostefa In your example slices list is created. I would like to add the PieSlice dynamically to slices. Is it possible ?
-
@dheerendra As far as i know we can not add elements dynamically inside a list of qqmllistproperty , but maybe other people can help you a little more.
-
@mostefa You are right. We are in same page. As the QQMLListProperty gets exposed as List to QML. List element in QML is not dynamically modifiable. Documentation was slightly confusing. May we can have bug to update the documentation to correctly reflect what it is.
Thank you for you support. I appreciate the same.