Model item cleanup?
-
wrote on 3 Oct 2011, 23:15 last edited by
When a model item is added to a model, does the model "own" the item for deletion purposes?
-
wrote on 3 Oct 2011, 23:45 last edited by
Which model items are you talking about?
-
wrote on 3 Oct 2011, 23:59 last edited by
For example, when I add a StandardModelItem to a StandardModel. Who is later responsible for deleting the StandardModelItem?
-
wrote on 4 Oct 2011, 00:10 last edited by
The model you added it into.
[quote]
QStandardItemModel::~QStandardItemModel ()Destructs the model. The model destroys all its items.
[/quote] -
wrote on 4 Oct 2011, 00:17 last edited by
Thanks. Sorry - I should have read more carefully.
-
wrote on 4 Oct 2011, 11:12 last edited by
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.
6/6