Search code examples
c++qt6

'class QTableView' has no member named 'model'


Accidentally, while writing the code, a part of the code containing "model()" in ui->tableView->model()->... stopped working. Although just 5 minutes ago the project was compiling successfully. Also in all my previous projects (I didn't touch them in any way and successfully ran them yesterday) that use "model()" anywhere in relation to QTableView in code, debugger also started showing the same error

Error message: In member function 'void menu::on_pbDelete_clicked()':
95:48: error: 'class QTableView' has no member named 'model'
QString id = ui->tableView->model()->data(ui->tableView->model()->index(selectedIndexes.first().row(), 0)).toString();

The error occurs here (and in all other cases of using "model()")
QString id = ui->tableView->model()->...
________________________________^~~~~

For understanding QModelIndexList selectedIndexes = ui->tableView->selectionModel()->selectedIndexes();


Solution

  • I solved the problem by asking a friend to type ui->tableView->model() in his QT and press Ctrl+LMB on model() and show me a screenshot. It turned out that in qabstractitemview.h (Ctrl+K qabstractitemview.h) for the virtual void setModel(QAbstractItemModel *model) I had once managed to enter an extra character that ruined the whole function