path: root/src
diff options
authorIvan Solovev <>2022-07-21 18:42:23 +0200
committerIvan Solovev <>2022-08-10 22:38:24 +0200
commitc4fabe37b9a97a189b02de4e72d040009892ad08 (patch)
treeb3466548b611b3f9b41be6b49d1b78bd424a62eb /src
parent2ca30440835ef99d8b5f720866fc163a9629bed7 (diff)
Remove QSqlTableModel::setQuery(const QSqlQuery &)
... and simply use the public methods of the base class instead. We can't completely remove it, so we just add it to removed_api.cpp By removing the setQuery() method in the QSqlTableModel class, we open up name lookup to the base class, where the const ref overload was already deprecated in 14f9f00fdb2dc428610c08e3d9d03e38e9602166, and the proper replacements were provided. [ChangeLog][QtSql][QSqlTableModel] The setQuery(const QSqlQuery &) method is removed, because QSqlQuery cannot be copied correctly. Use the public setQuery() overloads of the base QSqlQueryModel class instead. They allow passing of QSqlQuery by rvalue ref, or creation of the query by specifying query string and database object. Task-number: QTBUG-105048 Change-Id: I6f47067af6b4769578d4de9dbdbbbc7504ddf4ad Reviewed-by: Marc Mutz <>
Diffstat (limited to 'src')
3 files changed, 11 insertions, 15 deletions
diff --git a/src/sql/compat/removed_api.cpp b/src/sql/compat/removed_api.cpp
index cab5d5b528..ff223b9967 100644
--- a/src/sql/compat/removed_api.cpp
+++ b/src/sql/compat/removed_api.cpp
@@ -27,6 +27,13 @@ QSqlQuery QSqlQueryModel::query() const
+#include "qsqltablemodel.h"
+void QSqlTableModel::setQuery(const QSqlQuery &query)
+ QT_IGNORE_DEPRECATIONS(QSqlQueryModel::setQuery(query);)
#endif // QT_CONFIG(sqlmodel)
// #include <qotherheader.h>
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index 1fed690170..a6a8f68d20 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -342,10 +342,9 @@ bool QSqlTableModel::select()
- QSqlQuery qu(query, d->db);
- setQuery(qu);
+ setQuery(query, d->db);
- if (!qu.isActive() || lastError().isValid()) {
+ if (!d->query.isActive() || lastError().isValid()) {
// something went wrong - revert to non-select state
@@ -582,18 +581,6 @@ bool QSqlTableModel::clearItemData(const QModelIndex &index)
- This function simply calls QSqlQueryModel::setQuery(\a query).
- You should normally not call it on a QSqlTableModel. Instead, use
- setTable(), setSort(), setFilter(), etc., to set up the query.
- \sa selectStatement()
-void QSqlTableModel::setQuery(const QSqlQuery &query)
- QT_IGNORE_DEPRECATIONS(QSqlQueryModel::setQuery(query);)
Updates the given \a row in the currently active database table
with the specified \a values. Returns \c true if successful; otherwise
returns \c false.
diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h
index fc04d72a0d..8af3f84c59 100644
--- a/src/sql/models/qsqltablemodel.h
+++ b/src/sql/models/qsqltablemodel.h
@@ -99,7 +99,9 @@ protected:
virtual QString selectStatement() const;
void setPrimaryKey(const QSqlIndex &key);
void setQuery(const QSqlQuery &query);
QModelIndex indexInQuery(const QModelIndex &item) const override;
QSqlRecord primaryValues(int row) const;