PDA

View Full Version : Sqllite driver not loaded in qt 5.0.0



Wahib Idris
20th February 2013, 18:50
My sqllite driver is found but it is not loading .
I searched alot in my many websites but unfortunately no outcome.
I am using windows7 , sqlite3 database and qt 5.0... what I already did ..

- Add qt+= sql in .pro file
- copy sqlite.dll & sqllited.dll libraries in project folder.

It is throwing error while opening the database.Following are the error lines.

" QSqlite driver found.
QSqlite library loaded.
FATAL: Database failed to initialize!
Driver not loaded Driver not loaded
QSqlQuery::exec: database not open
failed"

PLease help me to solve this issue .... Below is my code snippet.


if (isDriverAvailable("QSQLITE")){
qDebug("QSqlite driver found.");

QLibrary sqlib("E:\\PROJECTS\\QT Project\\TaskAssistant\\TaskAssistant-build-Desktop_Qt_5_0_0_MSVC2010_32bit_SDK-Debug\\sqldrivers\\qsqlite.dll");
if (sqlib.load())
qDebug("QSqlite library loaded.");
else
qDebug(sqlib.errorString().toStdString().c_str());


addDatabase("QSQLITE");
setDatabaseName("E:\\PROJECTS\\QT Project\\TaskAssistant\\TaskAssistant\\db\\timeass istantdb");
//finally testing the connection
if (open()){
close(); //database finally opened. no need to do any thing else
qDebug("Database successfully connected.");
return;
}
else{
qCritical("FATAL: Database failed to initialize!");
QSqlError error = lastError();
qCritical( error.text().toStdString().c_str() );
}
}
else{
qCritical("FATAL: SQLITE driver doesn't exist!");
}

alrawab
20th February 2013, 22:15
QLibrary sqlib("E:\\PROJECTS\\QT Project\\TaskAssistant\\TaskAssistant-build-Desktop_Qt_5_0_0_MSVC2010_32bit_SDK-Debug\\sqldrivers\\qsqlite.dll");

why !!! ==>go to your executable dir ==>generate dir plugins\sqldrivers place qsqlite.dll(or qsqlited.dll if your build is debug ) ==>plugins\sqldrivers


toStdString().c_str()

!!!!!! check your code
http://www.developer.nokia.com/Community/Wiki/Creating_an_SQLite_database_in_Qt

ChrisW67
21st February 2013, 02:09
In a deployed application the Sql driver plugins should be in "%APPDIR%/sqldrivers", i.e. no "plugins/" directory.

As alrawab points out, you do not need to do anything to explicitly locate or load the driver DLL.

alrawab
21st February 2013, 08:11
:) sorry i meant "move the driver from QTDIR/plugins/sqldrivers to app sqldrivers "
my focus was focused on unnecessary conversions " qDebug(sqlib.errorString().toStdString().c_str());"
and "QLibrary sqlib("E:\\PROJECTS\\QT Project\\TaskAssistant\\TaskAssistant-build-Desktop_Qt_5_0_0_MSVC2010_32bit_SDK-Debug\\sqldrivers\\qsqlite.dl"