0

When it´s necessary manipulate a model of a TableView, it's necessary to get this model using the function tableView->model() . But, this returns a pointer to an QAbstractItem, and it's necessary one to a QAbstractModel.

So... I convert, using a dynamic cast, as shown bellow:

QStandardItemModel* model = dynamic_cast <QStandardItemModel*>
                                   (mWidgets->tableView->model());

But, this pointer returns NULL and I can't find out why.

Is there some initialization necessary?

Jones
  • 1,480
  • 19
  • 34

1 Answers1

1

QTableView::model() returns whatever model you gave it with QTableView::setModel(), it doesn't have one until you give it one.

Chris
  • 17,119
  • 5
  • 57
  • 60
  • Thank you very much, Chris! It's clear now: in my constructor class, I just added these lines: QStandardItemModel* model; model = new QStandardItemModel(); mWidgets->tableView ->setModel(model); So, now, I have gave a model to my TableView and everything works correctly! – André Vinícius Bezerra Jul 31 '12 at 17:59