QSqlQuery does not fit in a valid record

I am trying to select my database field, code:

if (db.db().isOpen()) { qDebug() << "OK"; QSqlQuery query("SELECT state FROM jobs WHERE jobId = '553'", db.db()); qDebug() << query.value(0).toString(); } else qDebug() << "No ok"; 

The query is correct because when I do qDebug () <<query.size, return 1.

but with qDebug () <query.value (0) .ToString (); to return:

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

How can i fix this?

Thank you very much.

+6
source share
1 answer

You must call query.first() to access the returned data. in addition, if your query returns more than one row, you must iterate through query.next() .

+17
source

Source: https://habr.com/ru/post/906830/


All Articles