Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QSqlTableModel: signals for after insert/update/delete and error?
lqsa last edited by
QSqlTableModel has the signals beforeInsert, beforeUpdate and beforeDelete, but:
- Is there any signal for afterInsert, afterUpdate and AfterDelete?
- For insert, QAbstractItemModel::rowsAboutToBeInserted would be the same as beforeInsert?
- For insert, QAbstractItemModel::rowsInserted was the equivalent to "afterInsert"?
- What happens if the insert fails? I suppose that first the rowsAboutToBeInserted and beforeInsert are launched, but, if the insert on the db fails, what signal I must to connect to detect it? the rowsInserted are launched?
JonB last edited by JonB
As you suggest, inherited from the base
rowsInserted/Removed(). These are raised after the insertion/deletion.
Update is a touch different. Assuming by that you mean that values in columns in an existing row are being updated, you would see a
For errors/behaviour, don't forget that your
QSqlTableModel::EditStrategydetermines when the changes are actually submitted to the database and hence when you would actually receive an error if that fails. I use
booland detailed error information. It's a good point and I don't know what the other edit strategies do for errors --- since Qt does not tend to use signals for this --- e.g.
QSqlTableModel::OnFieldChangepresumably causes the original
setData()to return a failure result(?), no idea for
VRonin last edited by
To add to the above, if I'm not mistaken, if the operation on the db fails the opposite signals will be emitted. For example:
rowsInserted-> db operation fails ->