Skip to content

Commit

Permalink
QSqlQueryModel test: don't copy a QSqlQuery
Browse files Browse the repository at this point in the history
Move the query into the model, and use a local scope to make sure that
we don't use the moved-from query later.

Pick-to: 6.9
Change-Id: I9d216e770733af8b0771280276dba0775209a802
Reviewed-by: Christian Ehrlicher <[email protected]>
Reviewed-by: Dheerendra Purohit <[email protected]>
  • Loading branch information
vohi committed Dec 16, 2024
1 parent d884aba commit af760da
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,13 @@ void tst_QSqlQueryModel::refreshQueryWithBoundValues()
QSqlDatabase db = QSqlDatabase::database(dbName);
QSqlQueryModel model;

QSqlQuery query(db);
query.prepare("SELECT name FROM " + qTableName("test", __FILE__, db) + " WHERE id = :id");
query.bindValue(":id", 1);
query.exec();
model.setQuery(query);
{
QSqlQuery query(db);
query.prepare("SELECT name FROM " + qTableName("test", __FILE__, db) + " WHERE id = :id");
query.bindValue(":id", 1);
query.exec();
model.setQuery(std::move(query));
}

QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.data(model.index(0, 0)).toString(), QString("harry"));
Expand Down

0 comments on commit af760da

Please sign in to comment.