From c4fabe37b9a97a189b02de4e72d040009892ad08 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Thu, 21 Jul 2022 18:42:23 +0200 Subject: [PATCH] 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 --- src/sql/compat/removed_api.cpp | 7 +++++++ src/sql/models/qsqltablemodel.cpp | 17 ++--------------- src/sql/models/qsqltablemodel.h | 2 ++ 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 QT_IGNORE_DEPRECATIONS(return query(QT6_CALL_NEW_OVERLOAD);) } +#include "qsqltablemodel.h" + +void QSqlTableModel::setQuery(const QSqlQuery &query) +{ + QT_IGNORE_DEPRECATIONS(QSqlQueryModel::setQuery(query);) +} + #endif // QT_CONFIG(sqlmodel) // #include 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() d->clearCache(); - 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 d->initRecordAndPrimaryIndex(); endResetModel(); @@ -581,18 +580,6 @@ bool QSqlTableModel::clearItemData(const QModelIndex &index) return setData(index, QVariant(), Qt::EditRole); } -/*! - 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 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); +#if QT_SQL_REMOVED_SINCE(6, 5) void setQuery(const QSqlQuery &query); +#endif QModelIndex indexInQuery(const QModelIndex &item) const override; QSqlRecord primaryValues(int row) const; };