1

I have a Qt application (non-GUI) running. I want to know the state in which my application exited so I can either restart it or mark it as completed successfully. Think of it as a simple shell script that wants to know this.

I'm using QCoreApplication::exit(errorCode) to exit the application but I'm not sure how and where to read this value.

Navjot Singh
  • 626
  • 1
  • 5
  • 16
  • I don't think there's anything Qt specific about this, so you might check this SO question: https://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line – MrEricSir Jan 22 '19 at 22:29
  • 1
    @MrEricSir You would still need to return the errorCode from main() – PiedPiper Jan 22 '19 at 22:31

1 Answers1

1

QCoreApplication::exit(errorCode) exits the event loop with a return value of errorCode.

int main(int argc, char**argv)
{
    QCoreApplication a(argc, argv);
    return a.exec();
}
...
a.exit(errorCode)

returns errorCode from the application

If you are using bash as a shell you can find the exit code of the last application in $?

bash$ echo $?
0
PiedPiper
  • 5,735
  • 1
  • 30
  • 40
  • I think I got the answer. QCoreApplication.exit() would only exit event loop and doesn't directly reflect the application status. On calling QCoreApplication::exec() it waits for the exit() method and return the code passed on to exit(errorCode). So I needed to return the code returned by QCoreApplication::exec(). If you can add this part to your answer, I'll accept that. – Navjot Singh Jan 22 '19 at 22:46
  • @DjokerS Look at the main() function I posted. It returns the value returned by QCoreApplication::exec() – PiedPiper Jan 22 '19 at 22:58
  • sorry missed that part! – Navjot Singh Jan 22 '19 at 23:06