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. Why QSqlQuery query.next() returns false

Why QSqlQuery query.next() returns false

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k 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.
  • M Offline
    M Offline
    Milica
    wrote on last edited by
    #1

    Hello... Why query.next() returns false, when query.isSelected() and query.isActive() return true. And datas for column numbers and index of EventNote are correct and i'm sure that there is data in the database. Here is the code:
    @
    QVector<QString> DataBase::GetEventNote(int eventId)
    {

     QSqlQuery query;
     query.prepare("SELECT * FROM Events WHERE idEvent=(?)");
     query.addBindValue("eventId");
    

    if(!query.exec()) // -> returns true
    {
    QMessageBox mb;
    mb.setText(query.lastError().text());
    mb.setWindowIcon(QIcon("icon.png"));
    mb.exec();
    }
    QVector<QString> debug1;
    bool v = query.isValid(); // -> returns false
    bool s = query.isSelect(); // -> returns true
    bool a = query.isActive(); // -> returns true
    bool b = query.first(); // -> returns false
    bool l = query.last(); // -> returns false
    bool p = query.previous(); // -> returns false
    QSqlRecord sr = query.record();
    int brsr = sr.count(); // -> returns correct number of columns
    QString str = query.lastQuery();

    const QSqlResult *r =query.result();

    int nameCol = sr.indexOf("EventNote"); // index of the field "EventNote" is correct (index 5)

    while (query.next()) // -> returns false
    {
    QString debug2 = query.value(nameCol).toString(); // output all EventNote
    debug1.push_back(debug2);
    }

    return debug1;
    }

    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      in your comments there are some strange values (first returns false, last returns false, ....).
      Can you print lastError after first()?

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Milica
        wrote on last edited by
        #3

        Somehow i fix this :)

        1 Reply Last reply
        0

        • Login

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