0

What is the recommended way to exit an application in Qt? I find the documentation quite confusing and I am lost through the various examples that I saw on the Internet.

I want to close a database if it does not open and I want the code to exit right there at that time, not to continue with the rest of the code.

Should I use:

1. exit(EXIT_FAILURE);
2. QObject::connect(&myApp, &MyApplication::quitApplication, &app, &QCoreApplication::quit,Qt::QueuedConnection);
3. QObject::connect(&myApp, &MyApplication::exitApplication, &app, &QCoreApplication::exit,Qt::QueuedConnection);
IceCode
  • 177
  • 1
  • 13
  • 3
    `connect` connects a slot with a signal, it does not terminate the program (unless you fire the signal of course) – 463035818_is_not_an_ai Jun 06 '23 at 08:49
  • 4
    `return` from `main()`. – Jesper Juhl Jun 06 '23 at 08:50
  • 3
    Keep in mind that `QCoreApplication::exit/quit()` will end the main event loop and return an exit code, but it won't end the program. It's still up to you to `return` that code from `main()` (for example). But the proper way to exit a program, whether or not Qt is involved, is to `return` from `main()` as already mentioned above. – Fareanor Jun 06 '23 at 09:05

0 Answers0