Important: Please read the Qt Code of Conduct -

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;

    QStringList driversList= QSqlDatabase::drivers();
    for(int i=0;i<driversList.size();i++)

    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!

  • Moderators

    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()": 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":

  • Chris Kawa, Thank you!
    It is OK, when I use absolute path for "plugins" .

  • Moderators

    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.

Log in to reply