There is a QTableView view, it displays a QSqlTableModel model. A search is organized via QSortFilterProxyModel , and the search results are placed in the same QTableView . A form QDataWidgetMapper created for editing records.

You need to check which model is currently active in QTableView and, based on this, call the correct QDataWidgetMapper binding.

Code form call methods:

 void MyForm::setMyModel(MySqlTableModel *myModel) { this->initForm(myModel); this->init(); } void MyForm::setMyProxyModel(QSortFilterProxyModel *proxy) { this->initForm(proxy); this->init(); } 

And there should be a valid check:

 void MainWindow::on_tableViewUi_doubleClicked(const QModelIndex &index) { this->myEditForm = new MyForm(); this->myEditForm->setParent(this, Qt::Window); this->myEditForm->setWindowModality(Qt::WindowModal); qDebug() << "Я ТУТ" << this->ui->tableViewUi->selectionModel()->model(); //возвращает модель if(this->ui->tableViewUi->selectionModel()->model() == QSqlTableModel//не работает) //а вот как проверить и выполнить if??? { this->myEditForm->setMyModel(this->mySqlTableModel); } if(this->ui->tableViewUi->selectionModel()->model() == QSortFilterProxyModel) //не работает... { this->myEditForm->setMyProxyModel(this->sortModel); } this->myEditForm->getMyMapper()->setCurrentModelIndex(index); this->myEditForm->show(); } 

    2 answers 2

    In Qt, all models are descendants of QAbstractItemModel , which in turn inherits from QObject . Accordingly, it becomes possible to check the type of an object using the QObject::inherits() method:

     QAbstractItemModel *model = this->ui->tableViewUi->selectionModel()->model(); if(model->inherits("QSqlTableModel") == true) { ... } else if(model->inherits("QSortFilterProxyModel") == true) { ... } 
    • option. I 'll try it now - Sakton

    Problem solved. All output from all methods to implement through QSortFilterProxyModel and checks are not needed.