QSqlDatabase with MYSQL management in the app
Solved
General and Desktop
-
Please show the complete code you are currently using.
You should also check if you have other QSqlDatabase objects lying around.
I don't have any member variable, only local variable
QSqlDatabase db = QSqlDatabase::database("TestConnection");
to get theDB
connection and use it to execute queries. It should deletes itself when it goes out of scope. So I think noQSqlDatabase
objects are lying around.More info available - warning remove database
-
The correct way is described in the documentation of the function:
void someFunction() { { QSqlDatabase db = QSqlDatabase::database("sales"); QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db); } // Both "db" and "query" are destroyed because they are out of scope QSqlDatabase::removeDatabase("sales"); // correct }