Note that there are some explanatory texts on larger screens.

plurals
  1. POQSqlDatabase works fine in Debug but not Release (QCoreApplication needed)
    text
    copied!<p>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:</p> <blockquote> <p>QSqlDatabase: QSQLITE driver not loaded</p> <p>QSqlDatabase: available drivers: </p> <p>QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins</p> </blockquote> <p>The only line that I think this could be from is this one which I just have at the top to make it global:</p> <pre><code>QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); </code></pre> <p>My PRO file is as follows:</p> <pre><code>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 </code></pre> <p>I've even tried reinstalling Qt to see if that fixes the problem.</p> <p>Just to reiterate...everything works just fine if I compile Debug. It's Release that the problems appear.</p> <p>I'm using Qt 4.7.3 and Visual Studio 2008 in case there's some sort of reason that might cause the issue.</p> <p><strong>UPDATE</strong></p> <p>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:</p> <pre><code>LessonsLearned::LessonsLearned(QWidget *parent) : QMainWindow(parent), ui(new Ui::LessonsLearned) { ui-&gt;setupUi(this); db = QSqlDatabase::addDatabase("QSQLITE"); } </code></pre> <p>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.</p> <p><strong>UPDATE 2</strong> I found something helpful here: <a href="https://stackoverflow.com/questions/5151279/qsqlite-driver-not-loaded-where-to-put-qt-database-driver-plugins">QSQLITE driver not loaded - where to put qt database driver plugins</a>. 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload