qt4到qt5使用qsqltablemodel的变化

时间:2021-07-08 23:16:42

查到了qt5的变更列表,在设计qsqltablemodel时有下面变化。


  1. QtSql
  2. -----
  3. QSqlQueryModel/QSqlTableModel/QSqlRelationalTableModel
  4. * The dataChanged() signal is now emitted for changes made to an inserted
  5. record that has not yet been committed. Previously, dataChanged() was
  6. suppressed in this case for OnRowChange and OnFieldChange. This was probably
  7. an attempt to avoid trouble if setData() was called while handling
  8. primeInsert(). By emitting dataChanged(), we ensure that all views are aware
  9. of the change.
  10. * While handling primeInsert() signal, the record must be manipulated using
  11. the provided reference. Do not attempt to manipulate the records using the
  12. model methods setData() or setRecord().
  13. * removeRows() no longer emits extra beforeDelete signal for out of range row.
  14. * removeRows() now requires the whole range of targetted rows to be valid
  15. before doing anything. Previously, it would remove what it could and
  16. ignore the rest of the range.
  17. * removeRows(), for OnFieldChange and OnRowChange, allows only 1 row to be
  18. removed and only if there are no other changed rows.
  19. * setRecord() and insertRecord()
  20. -The generated flags from the source record are preserved in the model
  21. and determine which fields are included when changes are applied to
  22. the database.
  23. -Require all fields to map correctly. Previously fields that didn't
  24. map were simply ignored.
  25. -For OnManualSubmit, insertRecord() no longer leaves behind an empty
  26. row if setRecord() fails.
  27. -setRecord() now automatically submits for OnRowChange.
  28. * QSqlQueryModel::indexInQuery() is now virtual. See
  29. QSqlTableModel::indexInQuery() as example of how to implement in a
  30. subclass.
  31. * QSqlQueryMode::setQuery() emits fewer signals. The modelAboutToBeReset()
  32. and modelReset() signals suffice to inform views that they must reinterrogate
  33. the model.
  34. * QSqlTableModel::select() is now a slot.
  35. * QSqlTableModel::selectRow(): This is a new slot that refreshes a single
  36. row in the model from the database.
  37. * QSqlTableModel edit strategies OnFieldChange/OnRowChange QTBUG-2875
  38. Previously, after changes were submitted in these edit strategies, select()
  39. was called which removed and inserted all rows. This ruined navigation
  40. in QTableView. Now, with these edit strategies, there is no implicit select()
  41. done after committing. This includes deleted rows which remain in
  42. the model as blank rows until the application calls select(). Instead,
  43. selectRow() is called to refresh only the affected row.
  44. * QSqlTableModel::isDirty(): New overloaded method to check whether model
  45. has any changes to submit. QTBUG-3108
  46. * QSqlTableModel::setData() and setRecord() no longer revert pending changes
  47. that fail upon resubmitting for edit strategies OnFieldChange and OnRowChange.
  48. Instead, pending (failed) changes cause new changes inappropriate to the
  49. edit strategy to be refused. The application should resolve or revert pending
  50. changes. insertRows() and insertRecord() also respect the edit strategy.
  51. * QSqlTableModel::setData() and setRecord() in OnRowChange no longer have the
  52. side effect of submitting the cached row when invoked on a different row.
  53. * QSqlDriver::subscribeToNotification, unsubscribeFromNotification,
  54. subscribedToNotifications, isIdentifierEscaped, and stripDelimiters
  55. are now virtual. Their xxxImplemenation counterparts have been removed
  56. now that QSqlDriver subclasses can reimplement these directly.

也就是说在setResord的时候需要将所有字段都匹配?