Saving data before SubmitAll()
-
I am editing a database using qsqltablemodel using TableView, and when entering unsuitable values, an error is returned, and the entered data is not saved, and if the error occurs in one cell, the entire row must be re-entered. Tell me how this can be fixed without removing the save button and without changing the database editing strategy
I tried to check the data before sending All(), but it doesn't help
Code example:if(!correct_data) { QMessageBox::warning(this,"Error","Data is not correct"); } else { model->submitAll(); }
If the data is incorrect, the program shows a Qmessagebox and deletes the data that has just been entered. How to fix it?
The gif shows an error when entering an unsuitable value according to the database conditions. The program automatically returns to the last saved values, although I did not prescribe this[GIF with error]
-
Hi and welcome to devnet,
What is the rest of the logic when you click on that button ?
How are you adding that row to your QTableView ? -
How are you adding that row to your QTableView ?
void admin_interface::on_pushButton_add_clicked() { model->insertRow(model->rowCount()); }
What is the rest of the logic when you click on that button?
Before I tried to check the data in the tableView it looked like this
void admin_interface::on_pushButton_refresh_clicked() { if(model->submitAll()) { } else if (model->lastError().text()==" No Fields to update") { qDebug()<<model->lastError().text(); QMessageBox::warning(this,"Error",""); } else { qDebug()<<model->lastError().text(); QString text = model->lastError().text(); QStringList lines = text.split( '\n' ); QMessageBox::warning(this,"Error",lines[0]); } model->setEditStrategy(QSqlTableModel::OnManualSubmit); row_count = model->rowCount(); }