QSqlTableModel: Updating record
Solved
General and Desktop
-
What is the cleanest way to update in QSqlTableModel? I do something like this:
QSqlTableModel adrTableModel; adrTableModel.setTable("address"); adrTableModel.setEditStrategy(QSqlTableModel::OnManualSubmit); adrTableModel.setFilter(filter); adrTableModel.select(); if (adrTableModel.rowCount() == 1) { QSqlRecord addressRecord = adrTableModel.record(0); addressRecord.setValue("isUsed", 1); adrTableModel.setRecord(0, addressRecord); adrTableModel.submitAll(); }
This works, but I am almost sure that there is an easier and cleaner way to update the record. What is the cleanest way to do it?
-
Hi,
Do you mean programmatically or through a GUI ?
In the first case, there's nothing particularly wrong with what you wrote.You can also use setData.