You have a little mess with all those parents and pointers
First few questions:
if (parent.isValid()) {
if (parent.isValid()) {
To copy to clipboard, switch view to plain text mode
What is parent is not valid (which is true for top level model items)?
parentItem = static_cast<GeometryItem*>(parent.internalPointer());
if (parentItem) {
parentItem = static_cast<GeometryItem*>(parent.internalPointer());
if (parentItem) {
To copy to clipboard, switch view to plain text mode
This will always be true (provided that you have a correct index() method in your model) but may be incorrect -- are you sure parent was not deleted before current item is deleted? While deleting an item you have to delete all its children first and not try to delete them after the parent item is deleted (so remove all references to them) and I don't see you do that in your code (and I guess it is hierarchical if you reference parent-child relation).
int nc = parentItem->childCount();
int nc = parentItem->childCount();
To copy to clipboard, switch view to plain text mode
if parentItem is invalid (and my guess is it is invalid) this will cause a segfault.
My general hint is that you try to avoid all these references to parents and grandparents.
I see another problem too:
#
QModelIndexList selIndexes = selections->selectedIndexes();
#
QItemSelectionModel *selections = selectionModel();
QModelIndexList selIndexes = selections->selectedIndexes();
To copy to clipboard, switch view to plain text mode
The last call may return indexes which are selected, but they may be (I don't know, please check that) indexes from the selection model and not the base model! And you're using them as indexes from the base model:
//...
gModel->removeRows(row_mom,1,ri);
QModelIndex ri = selIndexes.at(i);
//...
gModel->removeRows(row_mom,1,ri);
To copy to clipboard, switch view to plain text mode
You should build an index from the "gModel" from data obtained from the selection model.
Bookmarks