Console Application

  • Hi,
    i have written a small console application which I can use it in the command prompt.
    If i double click the exe file the command prompt opens and closes immediately.

    Is there a way that the command prompt do not close?

  • Qt Champions 2017


    • Is there a way that the command prompt do not close?

    Yes if your app do not close. :)
    Then command prompt stays open.

  • add char fake; std::cin >> fake; just before the return in your main() (you'll have to #include <iostream> if you don't already)

  • @mrjj

    The structure of the code is:

    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        QStringList arguments = a.arguments();
        // check arguments
        // do stuff and return

    I don't enter the main event loop. After checking all arguments and doing the stuff the application returns.

  • Add a.exec() at the end of your code in main. It shud stop

  • [I'm assuming you are on Windows] Without polluting your code, the correct way to use that .exe is:

    1. open the command prompt (cmd.exe)
    2. [optional] navigate with cd to the directory from which you want to start the program
    3. type the absolute path to your exe (use " around it to prevent failure due to spaces or other reserved chars in your path to interfere)

  • @VRonin

    You're right, thats exactly the way i use the application. But if you could skip the three steps by double clicking the .exe file, it would be very nice.

  • Qt Champions 2017


    well there is also

    cmd /k my_script.bat

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.