From 2ca30440835ef99d8b5f720866fc163a9629bed7 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 9 Aug 2022 12:42:59 +0200 Subject: Make QSqlQueryModel::query() return a reference to the const QSqlQuery Returning QSqlQuery instance by value does not make much sense, because it cannot be copied correctly. Also, its copy constructor and copy-assignment operators are deprecated from Qt 6.2. [ChangeLog][Potentially Source-Incompatible Changes][QSqlQueryModel] QSqlQueryModel::query() now returns a reference to the const QSqlQuery object associated with the model. Task-number: QTBUG-105048 Change-Id: I04a2aa377b17d770d2a9855040f8c730190484d8 Reviewed-by: Marc Mutz Reviewed-by: Edward Welbourne --- src/sql/compat/removed_api.cpp | 12 ++++++++++++ src/sql/models/qsqlquerymodel.cpp | 7 ++----- src/sql/models/qsqlquerymodel.h | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sql/compat/removed_api.cpp b/src/sql/compat/removed_api.cpp index 1ada26407a..cab5d5b528 100644 --- a/src/sql/compat/removed_api.cpp +++ b/src/sql/compat/removed_api.cpp @@ -17,6 +17,18 @@ QT_USE_NAMESPACE #if QT_SQL_REMOVED_SINCE(6, 5) +#if QT_CONFIG(sqlmodel) + +#include "qsqlquerymodel.h" +#include "qsqlquery.h" + +QSqlQuery QSqlQueryModel::query() const +{ + QT_IGNORE_DEPRECATIONS(return query(QT6_CALL_NEW_OVERLOAD);) +} + +#endif // QT_CONFIG(sqlmodel) + // #include // // implement removed functions from qotherheader.h // order sections alphabetically to reduce chances of merge conflicts diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp index 61620f81d4..fee99bd8ea 100644 --- a/src/sql/models/qsqlquerymodel.cpp +++ b/src/sql/models/qsqlquerymodel.cpp @@ -522,18 +522,15 @@ bool QSqlQueryModel::setHeaderData(int section, Qt::Orientation orientation, } /*! - Returns the QSqlQuery associated with this model. + Returns a reference to the const QSqlQuery object associated with this model. \sa setQuery() */ -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -QSqlQuery QSqlQueryModel::query() const +const QSqlQuery &QSqlQueryModel::query(QT6_IMPL_NEW_OVERLOAD) const { Q_D(const QSqlQueryModel); return d->query; } -QT_WARNING_POP /*! Returns information about the last error that occurred on the diff --git a/src/sql/models/qsqlquerymodel.h b/src/sql/models/qsqlquerymodel.h index ede97b04fb..73308b79e8 100644 --- a/src/sql/models/qsqlquerymodel.h +++ b/src/sql/models/qsqlquerymodel.h @@ -46,7 +46,10 @@ public: #endif void setQuery(QSqlQuery &&query); void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase()); +#if QT_SQL_REMOVED_SINCE(6, 5) QSqlQuery query() const; +#endif + const QSqlQuery &query(QT6_DECL_NEW_OVERLOAD) const; virtual void clear(); -- cgit v1.2.3