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:
void ThirdParties
::setLoans(QString id
) {
qDebug() << id;
queryLoans.prepare("SELECT loan_id, date, value, quotas, cancel_quotas, loan_type FROM tblLOANS WHERE thirdparty_id=:id");
queryLoans.bindValue(":id", id);
if (!queryLoans.exec())
QMessageBox::warning(this, tr
("Error en la consulta"), queryLoans.
lastError().
text());
loanIdComboBox->clear();
dateEdit->clear();
valueLineEdit->clear();
quotasLineEdit->clear();
cancelQuotasSpinBox->clear();
while (queryLoans.next())
{
qDebug() << queryLoans.value(0).toString();
loanIdComboBox->addItem(queryLoans.value(0).toString());
}
queryLoans.first();
dateEdit->setDate(queryLoans.value(1).toDate());
valueLineEdit->setText(queryLoans.value(2).toString());
quotasLineEdit->setText(queryLoans.value(3).toString());
loanTypeComboBox->setCurrentIndex(loanTypeComboBox->findText(queryLoans.value(5).toString()));
cancelQuotasSpinBox->setValue(queryLoans.value(4).toInt());
}
void ThirdParties::setLoans(QString id)
{
qDebug() << id;
QSqlQuery queryLoans;
queryLoans.prepare("SELECT loan_id, date, value, quotas, cancel_quotas, loan_type FROM tblLOANS WHERE thirdparty_id=:id");
queryLoans.bindValue(":id", id);
if (!queryLoans.exec())
QMessageBox::warning(this, tr("Error en la consulta"), queryLoans.lastError().text());
loanIdComboBox->clear();
dateEdit->clear();
valueLineEdit->clear();
quotasLineEdit->clear();
cancelQuotasSpinBox->clear();
while (queryLoans.next())
{
qDebug() << queryLoans.value(0).toString();
loanIdComboBox->addItem(queryLoans.value(0).toString());
}
queryLoans.first();
dateEdit->setDate(queryLoans.value(1).toDate());
valueLineEdit->setText(queryLoans.value(2).toString());
quotasLineEdit->setText(queryLoans.value(3).toString());
loanTypeComboBox->setCurrentIndex(loanTypeComboBox->findText(queryLoans.value(5).toString()));
cancelQuotasSpinBox->setValue(queryLoans.value(4).toInt());
}
To copy to clipboard, switch view to plain text mode
Bookmarks