You don't need to add additional library path, just move your sqldrivers directory to your application directory.
You don't need to add additional library path, just move your sqldrivers directory to your application directory.
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.
Qt Code:
#include <QtGui/QApplication> #include "TDPDataProcess.h" int main(int argc, char *argv[]) { TDPDataProcess w; w.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
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.
Qt Code:
int main(int argc, char *argv[]) { /*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);*/ TDPDataProcess w; w.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
Btw, you can try to link qsqlodbc plugin staticaly. So you don't need to worry about library path.
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.
I had try, It's does not work! and I added some test code to show the library path
Qt Code:
QString szt; for(int idx=0; idx<pathList.count(); idx++)To copy to clipboard, switch view to plain text mode
When exec this program on other PC, the dialog shown that the "xxx/plugins" had successfully added as 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
Bookmarks