Why QSqlQuery query.next() returns false
-
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;
}@
-
Hi,
in your comments there are some strange values (first returns false, last returns false, ....).
Can you print lastError after first()? -
Somehow i fix this :)