Execute exe(use qt database) from visual studio ,the execution results are wrong
-
i wrote a console application, code is
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
_tprintf(_T("Init failed\n"));
nRetCode = 1;
}
else
{
QApplication::addLibraryPath("./plugins");QStringList driversList= QSqlDatabase::drivers();
for(int i=0;i<driversList.size();i++)
{
QString one=driversList.at(i);
_tprintf(_T("%s!\n"),one.utf16());
}
}return nRetCode;
}my problem is ,if execute from vs2010 (debug or execute not debug),no one driver is found.But if execute console app from windows explorer ,all drivers are found. debug and release is same result. I don't know what's wrong with it. Please give me some advice,Thank you!
-
Hi, welcome to devnet,
Please use code tags when posting code (first button to the right).
It seems like working directory problem. When you run from VS "./plugins" translates to <solution dir>\plugins. When you run by clicking the exe it's <exe location>\plugins. When you run it from cmd it can be any folder you cd to. Instead of relative paths use something like "QCoreApplication::applicationDirPath()":http://qt-project.org/doc/qt-5.1/qtcore/qcoreapplication.html#applicationDirPath or place the plugins in standard subdirectory where exe is.
-
Please wrap your source code with @ when you post it the forum because it will be more readable.
Regarding the database drivers refer to documentation about building database drivers of the corresponding Qt version. For the newest version 5.2 please check "this link":http://qt-project.org/doc/qt-5/sql-driver.html#building-the-drivers-using-configure.
-
Great, just remember not to hardcode something like "C:\SomeFolder...". Not everyone has drive C ;) Use some universal Qt functions like the one I linked to.
Btw. If your problem is solved please prepend [SOLVED] to the thread title. It will let others know there's an answer here.