Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to quit a console application normally?



  • So, there it is:
    I have write a console application, recently, I found every time when i close the console window, my application not return a zero exit code, but

    D:\Development\QtProject\build-untitled-Desktop_Qt_5_14_0_MSVC2017_64bit-Debug\debug\untitled.exe exited with code -1073741510
    

    I thought it was my program that went wrong. but after a lot of test I found even a simple project just create still have this problem.

    I found some doc says this is because of event loop, but i can not remove event loop, I need it.

    the first is can i capture key event in a console application?
    then what should I do to make my application return 0 when exit.

    Thank you.



  • So where is the sourcecode for your simple console application? Folks cannot help if they cannot see what you tried.

    Also, console application means CONSOLE, not window. If you close the windoze CMD windows where the console application is running then it is going to abnormally terminate the program. If you don't want to get an error code then you must normally exit the console app BEFORE closing the window... or handle the termination signal from the shell...which could be haphazard in windoze.


  • Moderators

    @Mozzie said in How to quit a console application normally?:

    what should I do to make my application return 0 when exit.

    You must make your application shut down properly by calling QCoreApplication::quit().


Log in to reply