So I've heard that it's good programming when you close your database connection as soon as you don't need that connection and just re-open it when you do. So, I've been closing my connection whenever I don't need it, however I've noticed that it's slowed down my program significantly (it takes ~2 seconds per window to open). Any way to solve this?
I've defined QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
as a global, and just did db.open();
or db.close();
whenever I needed. In addition, if I just keep my connection open the whole time, my windows load instantly.
Edit: Reason why people say this is because connections could get dropped/disconnected midway through using your program and it could lead to unsaved data/big problems etc