Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Execute exe(use qt database) from visual studio ,the execution results are wrong
QtWS25 Last Chance

Execute exe(use qt database) from visual studio ,the execution results are wrong

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    duware
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leon.anavi
        wrote on last edited by
        #3

        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.

        http://anavi.org/

        1 Reply Last reply
        0
        • D Offline
          D Offline
          duware
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved