Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: QSqlQuery::isValid returns false

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    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.

  2. #22
    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 

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

    Default Re: QSqlQuery::isValid returns false

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

  4. #24
    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.

  5. #25
    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.