@thaidy said in QT Deploy QPSQL Plugin:
@hskoglund said in QT Deploy QPSQL Plugin:
what happens if you move the declaration into for example your MainWindow.h class:
QSqlDatabase DB;
DB = QSqlDatabase::addDatabase("QPSQL"):
IT WAS THAT, THANK YOU VERY MUCH!!
Glad this has solved problem, certainly better than some static variable.
However, this is still not right/advised. Per https://doc.qt.io/qt-5/qsqldatabase.html#details, red box warning:
Warning: It is highly recommended that you do not keep a copy of the QSqlDatabase around as a member of a class, as this will prevent the instance from being correctly cleaned up on shutdown. If you need to access an existing QSqlDatabase, it should be accessed with database(). If you chose to have a QSqlDatabase member variable, this needs to be deleted before the QCoreApplication instance is deleted, otherwise it may lead to undefined behavior.
Qt asks you to simply call
static QSqlDatabase QSqlDatabase::database(const QString &connectionName = QLatin1String(defaultConnection), bool open = true)
whenever you need to access a QSqlDatabase, and not to keep even a member variable QSqlDatabase around. You don't need it.