Qt - Clearing QTableView's contents

I would reset the model (if you do not need the data in the model later). Subclass your model (if it is a custom one) and implement a slot like;

void clear(){
   this->beginResetModel();
   ... // clear the content of your model here
   this->endResetModel();
{

Just check QAbstractItemView::reset().


The function myTableView->model() returns a QAbstractItemModel which does not contain the clear() method. You should call clear method of your model. If you have a model like:

QStandardItemModel * model= new QStandardItemModel( 2, 4 );

Calling clear should delete all data from the model erasing the view as a consequence as it is provided to show data in the associated model:

model->clear();