0

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:

  • Qt Creator 4.4.1
  • 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.

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

0

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.