Results 1 to 20 of 25

Thread: QSqlQuery::isValid returns false

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QSqlQuery::isValid returns false

    No, I mean Access databases can't jump across the result set regardless if you use Qt or not. If you want to reach the last entry, you have to iterate each record one by one until you reach the end.

  2. #2
    Join Date
    Feb 2008
    Posts
    154
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    12

    Default Re: QSqlQuery::isValid returns false

    but i have the program that deal with access database which is built using visual basic
    and this program go through the database easy it make last , first, next and previous
    and i want to rebuild this program using c++. it means that the database support non sequential access
    as well as sequential.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QSqlQuery::isValid returns false

    Maybe it emulates last() using next(). It doesn't say anything about either the database or the ODBC driver that handles it.

  4. #4
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQuery::isValid returns false

    Hello, I have a similar problem with an sqlite3 database.

    Queries work fine interactively, even queries work fine on the constructor, but on a slot give me this messages on console output:

    QSqlQuery::value: not positioned on a valid record
    QSqlQuery::value: not positioned on a valid record
    QSqlQuery::value: not positioned on a valid record
    QSqlQuery::value: not positioned on a valid record
    QSqlQuery::value: not positioned on a valid record

    I think each message is one for each field in the query string.

    The query is executed and the values are retrived, I can use this values without problems, but this messages bothers me, and dirty my console output.

    here the implementation of the slot:

    Qt Code:
    1. void ThirdParties::setLoans(QString id)
    2. {
    3. qDebug() << id;
    4. QSqlQuery queryLoans;
    5. queryLoans.prepare("SELECT loan_id, date, value, quotas, cancel_quotas, loan_type FROM tblLOANS WHERE thirdparty_id=:id");
    6. queryLoans.bindValue(":id", id);
    7. if (!queryLoans.exec())
    8. QMessageBox::warning(this, tr("Error en la consulta"), queryLoans.lastError().text());
    9. loanIdComboBox->clear();
    10. dateEdit->clear();
    11. valueLineEdit->clear();
    12. quotasLineEdit->clear();
    13. cancelQuotasSpinBox->clear();
    14.  
    15. while (queryLoans.next())
    16. {
    17. qDebug() << queryLoans.value(0).toString();
    18. loanIdComboBox->addItem(queryLoans.value(0).toString());
    19. }
    20. queryLoans.first();
    21. dateEdit->setDate(queryLoans.value(1).toDate());
    22. valueLineEdit->setText(queryLoans.value(2).toString());
    23. quotasLineEdit->setText(queryLoans.value(3).toString());
    24. loanTypeComboBox->setCurrentIndex(loanTypeComboBox->findText(queryLoans.value(5).toString()));
    25. cancelQuotasSpinBox->setValue(queryLoans.value(4).toInt());
    26. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QSqlQuery::isValid returns false

    Do the errors disappear when you comment out lines #20--#25?

  6. #6
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQuery::isValid returns false

    Don't dessapear. Even I commented all lines exept the declaration, prepare-bindValue and executed lines of the query, the message still appear.

    I repeat, this message appear only in this slot, on the constructor don't appear.

  7. #7
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlQuery::isValid returns false

    Hello. Now I solved my problem.

    The problem is using multiple connections (QObject::connect), the slot avobe call other signal i.e:

    Qt Code:
    1. connect(idComboBox, SIGNAL(currentIndexChanged(QString)),
    2. this, SLOT(setLoans(QString)));
    3.  
    4. connect(loanIdComboBox, SIGNAL(currentIndexChanged(int)),
    5. this, SLOT(setLoanValues(int)));
    To copy to clipboard, switch view to plain text mode 

    loanIdComboBox->clear(); call currentIndexChanged, on that connection I have the same query and for this behavior was the error.

    I correct this behavior using at begin of slot loanIdComboBox->blockSignals(true) and then on final of slot loanIdComboBox->blockSignals(false).

    DBG is a great help.

Similar Threads

  1. Replies: 4
    Last Post: 8th July 2007, 14:26
  2. connect returns false
    By krivenok in forum Qt Programming
    Replies: 6
    Last Post: 21st February 2006, 20:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.