[Qt-interest] Memory Management in Qt
Rohan McGovern
rohan.mcgovern at nokia.com
Tue Oct 26 08:14:53 CEST 2010
Ramesh said:
> HI all,
> I have small doubt about Qt memory management,
>
> Lets take an example of Listview, in listview we add each item by allocating memory dynamically. So in this case do we need to delete all the “new”ed items manually..
>
> Eg:
>
> Qlistview *list = new Qlistview;
> QStandardItemModel *mModel = new QStandardItemModel();
> list ->setModel(mModel);
>
> for(int I =0;i<10;i++)
> {
> QsandardItem *item = new QsandardItem(“Hi”);
> mModel->appendRow(item);
> }
>
> In this example, item should be deleted manually?
No - the model takes ownership of the item, it'll be deleted when the
model is deleted.
There is an exception if you use the take* functions, though - these
will cause the model to release ownership of items.
--
Rohan McGovern
QA Engineer
Qt Development Frameworks, Nokia
More information about the Qt-interest-old
mailing list