Answer the question
In order to leave comments, you need to log in
How to reflect row change/deletion from QSqlRelationTableModel in SQLite DB?
I am using a QTableView in conjunction with a QSortFilterProxyModel, a QSqlRelationalTableModel and a FlipProxyDelegate delegate (parent of the QSqlRelationalDelegate). Changing or deleting a row in a QTableView is not reflected in the database.
Tried to use QTableView with QSqlRelationalTableModel and QSqlRelationalDelegate didn't work
. Model creation code snippet:
QSqlRelationalTableModel * tableModel = new QSqlRelationalTableModel;
tableModel->setTable( currentTable );
tableModel->setEditStrategy( QSqlRelationalTableModel::OnManualSubmit );
createRelations( tableModel, currentTable );
filterView->setItemDelegate( new FlipProxyDelegate(tableModel) );
tableModel->select();
sortModel->setSourceModel( tableModel );
filterView->setModel( sortModel );
void InterfaceChanger::submit()
{
FilterTableView *filterView = (FilterTableView*)ui->layout->itemAt(0)->widget();
QSortFilterProxyModel * sortModel = (QSortFilterProxyModel *)filterView->getModel();
QSqlTableModel *model = (QSqlTableModel *)sortModel->sourceModel();
model->database().transaction();
if (model->submitAll())
{
model->database().commit();
model->select();
}
else
{
model->database().rollback();
QMessageBox::critical( nullptr,
"Ошибка",
model->lastError().databaseText());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question