Memory Management in Qt

岁酱吖の 提交于 2019-12-08 15:55:39

问题


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?


回答1:


QStandardItemModel takes ownership of items, so they will be automatically deleted when model is destroyed. You still need to delete the model itself (setModel() doesn't transfer ownership of model to the view, because one model can be used by multiple views).



来源:https://stackoverflow.com/questions/4021125/memory-management-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!