The QModelIndex should be used directly after being obtained and discarded directly after being used. The way to associate a certain QModelIndex with it's actual data is to use the internal pointer. When you implement the index() function, you provide the caller with the QModelIndex associated with the data you want to get:
return createIndex(row, column);
return createIndex(row, column);
To copy to clipboard, switch view to plain text mode
You can pass the createIndex function another piece of information, which is the internalId or the internalPointer:
RegItem *item = getItem(row, column, parentItem);
return createIndex(row, column, item);
RegItem *item = getItem(row, column, parentItem);
return createIndex(row, column, item);
To copy to clipboard, switch view to plain text mode
Using the internal pointer, you can also implement the parent() function.
Have a good look at the Editable Tree Model example.
Bookmarks