QSqlQuery :: prepare: open database

advertisements

I'm trying to do SELECT with DB MySql. This is code:

qDebug() << "status" << db.db().isOpen();
query.prepare("SELECT jobId FROM jobs");

and result is:

status true
QSqlQuery::prepare: database not open

How can I fix it?


Try passing the database in the constructor of the QSqlQuery:

QSqlQuery query(db.db());
query.prepare("SELECT jobId FROM jobs");