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 14f9f00fdb,
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 <marc.mutz@qt.io>
bb10
Ivan Solovev 2022-07-21 18:42:23 +02:00
parent 2ca3044083
commit c4fabe37b9
3 changed files with 11 additions and 15 deletions

View File

@ -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 <qotherheader.h>

View File

@ -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

View File

@ -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;
};