QSqlTableModel: signals for after insert/update/delete and error?
-
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?
-
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?
@lqsa said in QSqlTableModel: signals for after insert/update/delete and error?:
As you suggest, inherited from the base
QAbstractItemModelare signalsrowsInserted/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
QAbstractItemModel::dataChanged()signal.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 useQSqlTableModel::OnManualSubmit, andQSqlTableModel::submitAll()returns abooland 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 originalsetData()to return a failure result(?), no idea forQSqlTableModel::OnRowChange!