Delete a child of a QQuickItem
-
Hi,
I created a
Plotclass derived fromQQuickItemwhich displays x vs y plot curves. For the single plot curves I created aPlotCurveclass which is also derived fromQQuickItemand the plot curves are childs of thePlotobject. ThePlotobject has a vector of pointers to its childs.I am wondering how I can reset my
PlotObject to its original state. Simply callingdeleteordeleteLateron the adresses of the plot curves is not working.If it was c++ only I would probably delete the whole plot object, and create a new one. But as I instantiate the plot object in qml this is not an option.
How can I reset my object (remove its childs)?
-
Not quite clear about the question completed. If you want to delete the child object at QML, if you have identity property of QML object, you can say <id>.destroy() or iterate through the child objects using children property of an item and destroy them.
-
Sorry for the unclear question. How would I destroy it from c++? In c++ I got the object vis
QObject *qmlplotobject = rootObjects.value(0)->findChild<QObject*>("myPlot");This object has a member
QVector<PlotCurve *> _curves, but deleting the curves viafor(int i=0;i<_curves.size();i++) { delete _curves[i]; }does not work. The plot curves were created via an
add_curvefunction which calls the creator ofPlotCurve(derived vomQQuickItem) which also sets the parent of thePlotCurveto be thePlotobject.Is there something like a remove children function?
-
Here my stackoverflow post, where I tried to improve the question: https://stackoverflow.com/questions/50852203/qtquickscene-graph-delete-child-node