You have a number of problems in your attempt above ... First, you will need to iterate backwards because you will move the contents of the children down as you move (i.e. if you delete # 1, number # 2 will become a child # 1, and then you go to delete # 2, which will be the old child # 3).
Secondly, you need to access your children in different ways. The childAt () function is designed to search for a child on a specific x, y on the screen, and not in a list in a list.
Try this instead:
import QtQuick 1.0 Rectangle { width: 400 height: 400 Grid { id: contentGrid spacing: 10 Text { text: "foo" } // destroy this Text { text: "bar" } // destroy this as well } MouseArea { anchors.fill: parent onClicked: { for(var i = contentGrid.children.length; i > 0 ; i--) { console.log("destroying: " + i) contentGrid.children[i-1].destroy() } } } }
Wes hardaker
source share