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.
pathList.
append(QDir::current().
absolutePath()+"/plugins");
pathList.
append(QApplication::applicationDirPath()+"/plugins");
QStringList pathList=QApplication::libraryPaths();
pathList.append(QDir::current().absolutePath()+"/plugins");
pathList.append(QApplication::applicationDirPath()+"/plugins");
QApplication::setLibraryPaths(pathList);
To copy to clipboard, switch view to plain text mode
connect to database
bool TDPDataProcess::connectToDatabase(QString& szAccessFile)
{
"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;
}
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;
}
To copy to clipboard, switch view to plain text mode
Does anybody has some idea to solve this problem? Any help is appreciated
Bookmarks