QSqlQuery.setForwardOnly() causing next() to return false.
Unsolved
General and Desktop
-
I have upgraded our application from Qt5.3.1 to 5.15.10. The following code worked with 5.3.1 and no longer in 5.15.10.
*```
QString q("SELECT batch_name FROM batch_names");
qDebug() << "Query" << q;
QSqlQuery query(q,database);
qDebug() << query.numRowsAffected();
query.setForwardOnly(true);
if(query.lastError().type() == QSqlError::NoError)
{
if(query.first())
{
do
{
qDebug() << query.value(0);
ui.sTimeComboBox->addItem(query.value(0).toString());
} while (query.next());
}
}The output for this is: Query "SELECT batch_name FROM batch_names" 3 QVariant(QString, "B1") query.next() returns false after the first record. If I remove the query.setForwardOnly(true) line then the output is: Query "SELECT batch_name FROM batch_names" 3 QVariant(QString, "B1") QVariant(QString, "B2") QVariant(QString, "B3") The database is Postgres and the same query in pgAdmin returns: 
-
Please use correct code tags in your post so we can actually read your code. Also please provide a minimal, compilable example. setForwardOnly() works fine for me for postgres since ages.