Le 05/08/2016 à 00:54, John Weeks a écrit :
But when childAdded is called… child already has been added. That's the issue, 
model is not manipulating data, it's just supposed to react on their changes
OK, I finally decided to look at our code and the documentation :)

QAbstractItemModel has protected functions beginInsertRows and endInsertRows, 
as well as a few other beginXxx and endXxx functions. When data is added to the 
underlying data set, you call beginInsertRows(), do your work of packaging up 
QModelIndexes and inserting them, then call endInsertRows(). Since your 
subclass of QAbstractItemModel is only a representation of the data, not the 
data itself, you don't care of the childAdded signal comes after a data item 
has been added. At that point you prepare a new row in your QAbstractItemModel 
subclass.

When you say "packaging", you mean that you have a wrapper around the underlying data (something like a TreeItem class that "caches" data)? Main issue is not on adding rows (this you can indeed call begin while data is already added), issue is on removal since beginRemoveRows needs to access to the to-be-removed row, which is an issue if row has already been removed
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to