PDA

View Full Version : "Driver not loaded!"



bangqianchen
12th July 2010, 09:22
I am sorry to propose this question again, I tried many ways, still does not solve the problem.
My platform is VS2008+Qt4.6.0+Win7+Access database, The program (debug version, compiled with /MDd+Use Standard Windows Libraries) runing without problem on my PC, but report "driver not loaded" on another PC which QT is not installed. The program directory inforation is as below.

E:\TDPDATAPROCESS
| Microsoft.VC90.CRT.manifest
| Microsoft.VC90.DebugCRT.manifest
| msvcm90d.dll
| msvcp90d.dll
| msvcr90d.dll
| QtCored4.dll
| QtGuid4.dll
| QtSqld4.dll
| TDPDataProcess.exe
| TDPDataProcess.exe.intermediate.manifest
|
+---Database
| DPS_TSDB.mdb
|
\---plugins
\---sqldrivers
qsqlodbc4.dll
qsqlodbc4.lib
qsqlodbcd4.dll
qsqlodbcd4.lib


And part of my code is here:
In main.cpp, set the lib path.


QStringList pathList=QApplication::libraryPaths();
pathList.append(QDir::current().absolutePath()+"/plugins");
pathList.append(QApplication::applicationDirPath() +"/plugins");
QApplication::setLibraryPaths(pathList);


connect to database


bool TDPDataProcess::connectToDatabase(QString& szAccessFile)
{
QSqlDatabase connection = QSqlDatabase::addDatabase("QODBC");

QString dsn = QString(
"DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=%1").arg(szAccessFile);

connection.setDatabaseName(dsn);
if (!connection.open())
{
QMessageBox::warning(NULL,tr("Failed to connect database"),connection.lastError().text());
return false;
}

return true;
}


Does anybody has some idea to solve this problem? Any help is appreciated

wysota
12th July 2010, 09:31
Does the first snippet run before QApplication constructor or after it?

Lykurg
12th July 2010, 09:32
Is the directory sqldrivers inside plugins? And you also can try to use qt.conf inside the root directory.

bangqianchen
12th July 2010, 10:22
1. The program is OK on my computer, and the program is started on the other PC, but reporting error when connect to the database.

2. sqldrivers inside plugins directory. BWT, what's this mean? "try to use qt.conf inside the root directory", I am on the window platform.

wysota
12th July 2010, 10:28
Please answer my question.

Lykurg
12th July 2010, 10:30
BWT, what's this mean? "try to use qt.conf inside the root directory", I am on the window platform.
See http://doc.trolltech.com/4.6/qt-conf.html

What I did is, make a sample application (or alter your existing) and print QCoreApplication::libraryPaths() to a file/message popup/... and see where Qt looks for the plugins.

EDIT: again 2nd.

saa7_go
12th July 2010, 10:47
You don't need to add additional library path, just move your sqldrivers directory to your application directory.

bangqianchen
12th July 2010, 11:13
I am sorry, my english is poor and misunderstand "Does the first snippet run before QApplication constructor or after it? "
the code is after QApplication constructor, the following is the code.



#include <QtGui/QApplication>
#include "TDPDataProcess.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QStringList pathList=QApplication::libraryPaths();
pathList.append(QDir::current().absolutePath()+"/plugins");
pathList.append(QApplication::applicationDirPath() +"/plugins");
QApplication::setLibraryPaths(pathList);

QTextCodec* codec = QTextCodec::codecForLocale();
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);

TDPDataProcess w;
w.show();
return a.exec();
}

bangqianchen
12th July 2010, 11:30
You don't need to add additional library path, just move your sqldrivers directory to your application directory.

I had try, It's does not work! and I added some test code to show the library path



QStringList pathList=QApplication::libraryPaths();
pathList.append(QDir::current().absolutePath()+"/plugins");
pathList.append(QApplication::applicationDirPath() +"/plugins");
QApplication::setLibraryPaths(pathList);

QString szt;
for(int idx=0; idx<pathList.count(); idx++)
szt += pathList.at(idx) + QObject::tr("\n");
QMessageBox::warning(NULL,QObject::tr("Library path"),szt);


When exec this program on other PC, the dialog shown that the "xxx/plugins" had successfully added as library path.

saa7_go
12th July 2010, 12:20
I had try, It's does not work! and I added some test code to show the library path

What do you mean it's does not work? The driver is not loaded?

When you move your sqldrivers directory to your application directory, does your files and direcotory structures look like this:

E:\TDPDATAPROCESS
| Microsoft.VC90.CRT.manifest
| Microsoft.VC90.DebugCRT.manifest
| msvcm90d.dll
| msvcp90d.dll
| msvcr90d.dll
| QtCored4.dll
| QtGuid4.dll
| QtSqld4.dll
| TDPDataProcess.exe
| TDPDataProcess.exe.intermediate.manifest
|
+---Database
| DPS_TSDB.mdb
|
+---sqldrivers
| qsqlodbcd4.dll

wysota
12th July 2010, 14:11
You need to set library paths for QApplication before creating the application object. The methods you need to call are static so they can be called without an object. If you use them after the application object is already created, plugins will not be loaded as they are loaded in the constructor of the application object.

bangqianchen
13th July 2010, 02:37
You need to set library paths for QApplication before creating the application object. The methods you need to call are static so they can be called without an object. If you use them after the application object is already created, plugins will not be loaded as they are loaded in the constructor of the application object.

Thanks for replying, however, it sames not the case, I had try as you suggested.



int main(int argc, char *argv[])
{
QStringList pathList=QApplication::libraryPaths();
pathList.append(QDir::current().absolutePath()+"/plugins");
pathList.append(QApplication::applicationDirPath() +"/plugins");
QApplication::setLibraryPaths(pathList);

/*QString szt;
for(int idx=0; idx<pathList.count(); idx++)
szt += pathList.at(idx) + QObject::tr("\n");
QMessageBox::warning(NULL,QObject::tr("Library path"),szt);*/

QApplication a(argc, argv);

QTextCodec* codec = QTextCodec::codecForLocale();
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);

TDPDataProcess w;
w.show();
return a.exec();
}

saa7_go
22nd July 2010, 14:43
Btw, you can try to link qsqlodbc plugin staticaly (http://doc.trolltech.com/4.6/plugins-howto.html#static-plugins). So you don't need to worry about library path.

pamalite
22nd July 2010, 15:03
I had the same problem with Qt4.6 on WinXP.

I tried addLibraryPath() and setLibraryPaths(). Also tried qt.conf file. Nothing seemingly worked. It will always fallback to %QT_DIR%/plugins directory.

Last resort, I added QT_PLUGIN_PATH in the system environment variable, copied sqldrivers/ into the root directory of the EXE file, it works!

I added QT_PLUGIN_PATH with the value . (a dot) to signify look at the current directory.