Model item cleanup?
-
When a model item is added to a model, does the model "own" the item for deletion purposes?
-
Which model items are you talking about?
-
For example, when I add a StandardModelItem to a StandardModel. Who is later responsible for deleting the StandardModelItem?
-
The model you added it into.
[quote]
QStandardItemModel::~QStandardItemModel ()Destructs the model. The model destroys all its items.
[/quote] -
Thanks. Sorry - I should have read more carefully.
-
Caution! The model does not always delete the items!
If you use one of the takeXX methods, like "QStandardItemModel::takeItem() ":http://doc.qt.nokia.com/4.7/qstandarditemmodel.html#takeItem, the item is removed from the model, but it is not deleted! You get back a pointer (or a list of pointers) to the item(s) and you can reinsert the item in the same or another model or you must delete it manually to avoid a memory leak.