Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - Clearing QTableView's contents [closed]

I am working in Qt 4.7, and have a dialog containing (among other, unrelated things) a QTableView and a QButton. When the QButton is clicked, it must clear all the data from the QTableView. I am unsure on how to accompish this. I've looked around online for a while, but haven't found anything too helpful. Based on what I found here, I tried this:

void MyClass::on_myButton_clicked() { myTableView->model()->clear(); }

However, this gave the following error:

error: C2039: 'clear' : is not a member of 'QAbstractItemModel'

Is there another way to do this that I am accidentally overlooking? Thanks!

like image 355
thnkwthprtls Avatar asked Apr 07 '14 15:04

thnkwthprtls


1 Answers

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();
like image 147
Nejat Avatar answered Sep 21 '22 03:09

Nejat