kiriloff
kiriloff

Reputation: 26335

QList and delete

I have a QList with pointers to objects with class type Model. I would like to delete appropriately this QList after it has being used. I know Qt philosophy is to avoid C-style memory management. How do I delete this QList?

Upvotes: 16

Views: 18199

Answers (2)

Unihedron
Unihedron

Reputation: 11041

As seen from an earlier revision, this was OP's approach:

QList<Model*>lstMdls;

get Data(lstMdls);
 /*
  * Do other things
  */
for(int i=0;i<lstMlds.size();i++)
{
    delete lstMdls.first();
}

Upvotes: 0

sgibb
sgibb

Reputation: 25726

You could use qDeleteAll:

qDeleteAll(lstMdls);

lstMdls.clear();

Upvotes: 28

Related Questions