Home > Mobile >  create object by new in on_pushButton_clicked() so where can i delete that object
create object by new in on_pushButton_clicked() so where can i delete that object

Time:12-12

void MainWindow::on_pushButton_clicked()
{
  Model *model = new Model;
  ui->tableView->setModel(model);
}

Where can I delete model object, please help.

CodePudding user response:

You can just do

  Model *model = new Model(this);

This will set MainWindow as parent of the Model. MainWindow will delete the object when it gets destroyed itself.

Read more https://doc.qt.io/qt-5/objecttrees.html

  • Related