c++sqliteqtqtsqlqsqldatabase

"QSqlDatabase: QSQLITE driver not loaded" error only in Debug Mode


I am attempting within my code to connect to an SQLite database:

bool MainWindow::connOpen(){

mydb=QSqlDatabase::addDatabase("QSQLITE");

//qDebug ( )  <<  QSqlDatabase::drivers();

QString dbpath = "dbname.sqlite";
mydb.setDatabaseName(dbpath);
}

Which gives me the error message:

QSqlDatabase: QSQLITE driver not loaded

As well as an error window:

Driver not Loaded Driver not Loaded

The QSqlDatabase mydb declaration is in the MainWindow header file.

Strangely, this only happens in Debug Mode, in Release Mode, everything is fine. Even weirder, this used to work before (I think) an automatic Qt Update.

I am using:

Also, I checked the sqlite.dll is within the sqldrivers folders, where I understand it should be. But for some reason the Qt Folder is called Qt 5.9.1, unlike my actual version, only this does not seem to have any effect. Everything else works fine.

Also, when I uncomment the QSqlDatabase::drivers(); line, the output in Debug Mode is:

()

While in Release Mode, I get:

("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7")

Clearly, the drivers are not being found.

Where does the difference between debug and release could come from?


Solution

  • The fact that release builds work, but debug fails is because on Windows there are actually 2 files per plugin — in this case qsqlite.dll and qsqlited.dll. The one with the d is used for debug builds, and the other one for release builds.

    As the debug variant is missing, a reinstallation of Qt is the only way to get back the missing files.