Hi,
deleting Grid items this way still does not produce a crash for me.
Which platform are you testing on? I tried the code on macOS desktop and iOS without crashes.
Anyway, as an alternative solution you could try to let a QML Repeater handle the object creation and removal?
I think this would be a cleaner approach than manually creating and removing items:
import QtQuick
import Felgo
App {
NavigationStack {
AppPage {
title: "Test"
Grid {
id: myGrid
columns: 3
spacing: 2
property var gridItems: ["red","green","blue","cyan","magenta"]
Repeater {
id: itemRepeater
model: myGrid.gridItems
Rectangle { color: modelData; width: 50; height: 50 }
}
}
Column {
anchors.top: myGrid.bottom
AppButton {
text: "Add"
onClicked: {
myGrid.gridItems.push("green")
myGrid.gridItemsChanged()
}
}
AppButton {
text: "Remove"
onClicked: {
console.log(itemRepeater.count)
let removed = myGrid.gridItems.pop()
myGrid.gridItemsChanged()
console.log(itemRepeater.count, "removed:", removed)
}
}
}
}
}
}