[Interest] Design Issue with QAbstractItemModel & QTreeView

John Weeks john at wavemetrics.com
Fri Aug 5 00:54:23 CEST 2016


> 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.

Where does your data come from? How do you know when new data is added to the underlying data set?

-John Weeks




More information about the Interest mailing list