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(); }