PDA

View Full Version : App found qsqlite4.dll driver file but still "Driver not loaded"



merelendor
16th August 2011, 03:44
Excuse me for my, possible, bad english :) I have a trouble with including qsqlite driver with my app. I have read a lot about including qsqlite4.dll with package on qtcentre or stackoverflow, but in my situation all of this solutions don't work. I downloaded QtSQK 4.7.3 with QtCreator and wrote a small app with Sqlite usage. I created the "plugins/sqldrivers" dir in my release output folder, found qsqlite4.dll (478720 bytes - in "/mingw/plugins/sqldrivers" folder), put it into the "plugins/sqldrivers" dir. Added the
a.addLibraryPath(a.applicationDirPath()+"/plugins"); into main.cpp. After this i saw that
qDebug() << a.libraryPaths(); //where a is QApplication will output "("app/release/plugins", "C:/QtSDK/Desktop/Qt/4.7.3/mingw/plugins", "app/release")", and through Resource Monitor in Win7 i see that qsqlite4.dll loaded when my app start and work fine with SQL. Then, i want to check, will it work on clear system without QT. If i rename the "C:/QtSDK/Desktop/Qt/4.7.3/mingw/plugins" to some like "plugins__", i see, that my app have only 2 paths - "..../release/plugins" and "..../release". In all that situations my QSqlDatabase found the QSQLITE driver -
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.drivers() will output "QSQLITE". But, when i try to use qsqlite4.dll from my app bundle, i got a error from QSqlDatabase "Driver not loaded Driver not loaded". If i remove qsqlite4.dll from "myapp/plugins/sqldrivers" dir QSqlDatabase will not found them (db.drivers() return nothing), so i think i have a situation when driver DLL is founded by my app, but does not load. Why?

Trying not to use "app/plugins/sqldrivers/qsqlite4.dll" dir but use "app/sqldrivers/qsqlite4.dll" instead without adding a libraryPath does nothing, QSqlDatabase even does not found the driver and return nothing with db.drivers()..

It's like:
1.
app/plugins/sqldrivers/qsqlite4.dll
QtSDK/Desktop/Qt/4.7.3/mingw/plugins/sqldrivers/qsqlite4.dll - app use this file, all fine

2. app/plugins/sqldrivers/qsqlite4.dll - driver found, not loaded (with adding libraryPath "plugins");

3. app/sqldrivers/qsqlite.dll - driver not found, not loaded

In advance thank you all for the information..

merelendor
17th August 2011, 01:04
After hours of dance with tambourine i found a solution: in my project the QSqlDatabase definition is in MainWindow class before MainWindow initialization (for class scope), and apparently the qsqlite4.dll does not initialized before that step. I do not understand why this don't happened when i used "QTDIR/mingw/plugins" (by default) as plugins folder, but when i rewrite QSqlDatabase initialization it work fine with deployment dll.

Old, work fine only with QTDIR/mingw/plugins:

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
}


New, work fine with deployment dll:


QSqlDatabase db = QSqlDatabase();
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
db = db.addDatabase("QSQLITE");
}


Be careful not to repeat my mistakes :)

nish
17th August 2011, 11:15
You should never store the QSqlDatabase object anywhere. Use the static functions to the the database on a local variable and let it go out of scope. Use of global is not recommended.