0
votes

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 ist fine. Even weirder, this used to work before (I think) an automatic QT Update. I am using QTCreator 4.4.1 and QT 5.9.2. 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.

Does anybody have an idea where the difference betweeen debug and release could come from? Thanks a lot!

2
Can you find the qsqlited.dll as well (note the d suffix)? If it's missing, your Qt installation is propably broken. In that case you need to reinstall Qt (make shure to use the online installer) - Felix
Oh deary me, yes. I suspected something like this, but in my google search it never shoiwed up and I didn't miss them since they weren't there. Not sure if they disappeared or what happened exactly, but after a reinstallation it works now. Thanks a lot! - user30248

2 Answers

1
votes

To summarize as an answer:

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.

-1
votes

In my case: So does not work:

db = QSqlDatabase::addDatabase("QSQLITE", "MyConnection"); //MyConnection as connection name - Driver not loaded

and it works:

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

Both versions work in Release.

QT 5.10