Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSqlQuery::prepare: database not open

Tags:

c++

mysql

qt

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?

like image 301
Jjreina Avatar asked Mar 01 '26 20:03

Jjreina


1 Answers

Try passing the database in the constructor of the QSqlQuery:

QSqlQuery query(db.db());
query.prepare("SELECT jobId FROM jobs");
like image 150
pnezis Avatar answered Mar 04 '26 09:03

pnezis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!