Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using VS2008 & QT plugin to make my application. After making package when I am running the application I am getting error :

QSqlDatabase: QSQLITE driver not loaded
QSqlDatabase: available drivers: 
Database error: QSqlError(-1, "Driver not loaded", "Driver not loaded") 
QSqlError(-1, "Driver not loaded", "Driver not loaded") 

I have added the qsqlite.dll to my package & also changed the libpath. But still I am getting this error. How to solve this.

My Code::

  QStringList str;
str.append(".");
a.setLibraryPaths(str);
a.addLibraryPath("./sqldrivers/");

//a.addLibraryPath(".");

qDebug()<<"my library path : "<<a.libraryPaths();

QLibrary sqlib("qsqlite4.dll");
sqlib.load();
qDebug()<<"my library loaded"<<sqlib.isLoaded();

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
qDebug()<<"Database error:"<<db.lastError();

db.setDatabaseName("vimukti1234");
qDebug()<< db.lastError();

 db.open();
QSqlQuery query;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
533 views
Welcome To Ask or Share your Answers For Others

1 Answer

The drivers need to be placed under "sqldrivers", not in the same directory as the executable (they are loaded on runtime, and Qt looks for them in "sqldrivers"). A typical structure of one of our installed applications is like this:

.:
total 26616
-rwxr-xr-x 1 root root 2245632 Sep 29 03:53 AlvaEditor.exe
-rwxr-xr-x 1 root root 2335232 Sep 29 03:53 QtCore4.dll
-rwxr-xr-x 1 root root 8421376 Sep 29 03:53 QtGui4.dll
-rwxr-xr-x 1 root root  199168 Sep 29 03:53 QtSql4.dll
-rwxr-xr-x 1 root root  306688 Sep 29 03:53 libctemplate.dll
-rwxr-xr-x 1 root root   26624 Sep 29 03:53 qgif4.dll
-rwxr-xr-x 1 root root   28672 Sep 29 03:53 qico4.dll
-rwxr-xr-x 1 root root  200704 Sep 29 03:53 qjpeg4.dll
-rwxr-xr-x 1 root root  222720 Sep 29 03:53 qmng4.dll
-rwxr-xr-x 1 root root  439808 Sep 29 03:53 qsqlite4.dll
-rwxr-xr-x 1 root root   21504 Sep 29 03:53 qsvg4.dll
-rwxr-xr-x 1 root root  287232 Sep 29 03:53 qtiff4.dll
drwxr-xr-x 2 root root    4096 Sep 29 03:53 sqldrivers

./sqldrivers:
total 432
-rwxr-xr-x 1 root root 439808 Sep 29 03:53 qsqlite4.dll

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...