Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQuery.setForwardOnly() causing next() to return false.
Forum Update on Monday, May 27th 2025

QSqlQuery.setForwardOnly() causing next() to return false.

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 192 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lex003
    wrote on 28 Oct 2022, 20:24 last edited by
    #1

    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:
    ![a1f281f7-1d0f-4a79-98ae-861571d0cc96-image.png](https://ddgobkiprc33d.cloudfront.net/b58b9d16-d96d-4196-9ebe-29960a0faa13.png)
    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 29 Oct 2022, 08:51 last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0

      1/2

      28 Oct 2022, 20:24

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved