您的位置:首页 > 编程语言 > Qt开发

qt4到qt5使用qsqltablemodel的变化

2015-03-10 07:08 363 查看
查到了qt5的变更列表,在设计qsqltablemodel时有下面变化。

QtSql
-----
QSqlQueryModel/QSqlTableModel/QSqlRelationalTableModel

* The dataChanged() signal is now emitted for changes made to an inserted
record that has not yet been committed. Previously, dataChanged() was
suppressed in this case for OnRowChange and OnFieldChange. This was probably
an attempt to avoid trouble if setData() was called while handling
primeInsert(). By emitting dataChanged(), we ensure that all views are aware
of the change.

* While handling primeInsert() signal, the record must be manipulated using
the provided reference. Do not attempt to manipulate the records using the
model methods setData() or setRecord().

* removeRows() no longer emits extra beforeDelete signal for out of range row.

* removeRows() now requires the whole range of targetted rows to be valid
before doing anything. Previously, it would remove what it could and
ignore the rest of the range.

* removeRows(), for OnFieldChange and OnRowChange, allows only 1 row to be
removed and only if there are no other changed rows.

* setRecord() and insertRecord()
-The generated flags from the source record are preserved in the model
and determine which fields are included when changes are applied to
the database.
-Require all fields to map correctly. Previously fields that didn't
map were simply ignored.
-For OnManualSubmit, insertRecord() no longer leaves behind an empty
row if setRecord() fails.
-setRecord() now automatically submits for OnRowChange.

* QSqlQueryModel::indexInQuery() is now virtual. See
QSqlTableModel::indexInQuery() as example of how to implement in a
subclass.

* QSqlQueryMode::setQuery() emits fewer signals. The modelAboutToBeReset()
and modelReset() signals suffice to inform views that they must reinterrogate
the model.

* QSqlTableModel::select() is now a slot.

* QSqlTableModel::selectRow(): This is a new slot that refreshes a single
row in the model from the database.

* QSqlTableModel edit strategies OnFieldChange/OnRowChange QTBUG-2875
Previously, after changes were submitted in these edit strategies, select()
was called which removed and inserted all rows. This ruined navigation
in QTableView. Now, with these edit strategies, there is no implicit select()
done after committing. This includes deleted rows which remain in
the model as blank rows until the application calls select(). Instead,
selectRow() is called to refresh only the affected row.

* QSqlTableModel::isDirty(): New overloaded method to check whether model
has any changes to submit. QTBUG-3108

* QSqlTableModel::setData() and setRecord() no longer revert pending changes
that fail upon resubmitting for edit strategies OnFieldChange and OnRowChange.

Instead, pending (failed) changes cause new changes inappropriate
to the

edit strategy to be refused. The application should resolve or revert pending
changes. insertRows() and insertRecord() also respect the edit strategy.

* QSqlTableModel::setData() and setRecord() in OnRowChange no longer have the
side effect of submitting the cached row when invoked on a different row.

* QSqlDriver::subscribeToNotification, unsubscribeFromNotification,
subscribedToNotifications, isIdentifierEscaped, and stripDelimiters
are now virtual. Their xxxImplemenation counterparts have been removed
now that QSqlDriver subclasses can reimplement these directly.

也就是说在setResord的时候需要将所有字段都匹配?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt4 qt5