I have an application that is using SQLite within Qt using QSqlDatabase and everything works just fine if I compile in Debug mode. My problem is that, when I switch to Release mode nothing works. My first errors seemed to be related to the code bringing in the QtCore4.dll and QtGui4.dll files. Once I moved those files into the same directory as the compiled code, the program then loaded but the following error was written to the Qt Creator console:
QSqlDatabase: QSQLITE driver not loaded
QSqlDatabase: available drivers:
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
The only line that I think this could be from is this one which I just have at the top to make it global:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
My PRO file is as follows:
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = LessonsLearned
TEMPLATE = app
SOURCES += main.cpp\
lessonslearned.cpp
HEADERS += lessonslearned.h
FORMS += lessonslearned.ui
I've even tried reinstalling Qt to see if that fixes the problem.
Just to reiterate...everything works just fine if I compile Debug. It's Release that the problems appear.
I'm using Qt 4.7.3 and Visual Studio 2008 in case there's some sort of reason that might cause the issue.
UPDATE
I've moved the declaration of "QSqlDatabase db" inside the header file for the class and have it as private. I've also moved the call to addDatabase("QSQLITE") to the constructor:
LessonsLearned::LessonsLearned(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::LessonsLearned)
{
ui->setupUi(this);
db = QSqlDatabase::addDatabase("QSQLITE");
}
This made the error about needing QCoreApplication dissappear, but I still get the first two messages. Still works in Debug but not Release. I'm wondering if the program is still pointing to a wrong DLL somewhere. I've tried dependency walker some more, but I haven't been able to find one that's wrong, yet.
UPDATE 2 I found something helpful here: QSQLITE driver not loaded - where to put qt database driver plugins. I think this is the same issue that I had. I still don't know why I had to modify the Release directory to add a sqldrivers folder, but it works.
sqldrivers/qsqlite.dllfor release,which locate atC:\Qt\Qt5.6.0\5.6\mingw49_32\plugins\sqldrivers- KunMing Xie