0
votes

let's say I decide to randomly remove a few items from my model. I have the references to those items but that's not enough to call the beginRemoveRows() method properly. It needs to know the QModelIndex for each item.

But to get the QModelIndex for an item, I need to know the QModelIndex for the parent as well!

virtual QModelIndex     index(int row, int column, const QModelIndex & parent = QModelIndex()) 

Only the RootItem doesn't have a parent and therefore doesn't need a QModelIndex. So I would need to start from there and recursively traverse through all children until I end up with the appropriate QModelIndex for each item if this is the correct way of doing things.

Is there a better way to get the QModelIndex for a random item?

1

1 Answers

0
votes

Never mind. Apparently I can just use the createIndex method to make a QModelIndex for my item.

QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, void *adata) const