QList and delete

前端 未结 2 1894
粉色の甜心
粉色の甜心 2021-02-08 03:40

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

相关标签:
2条回答
  • 2021-02-08 04:17

    You could use qDeleteAll:

    qDeleteAll(lstMdls);
    
    lstMdls.clear();
    
    0 讨论(0)
  • 2021-02-08 04:32

    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();
    }
    
    0 讨论(0)
提交回复
热议问题