QML language has a global object called Qt
which provides many useful enums and functions. Probably the most common used function of this object is quit()
. This function causes to emit QQmlEngine::quit()
signal, usually connected to QCoreApplication::quit()
slot by the application developer.
But the problem is, this function calls QCoreApplication::exit()
with return code 0.
My question is, is there a native way to tell the application to exit with a specified return code from QML? With "native", I mean a direct way instead of a work around or a hack(for ex., calling an invokable function).
This function causes the QQmlEngine::quit() signal to be emitted. Within the Prototyping with qmlscene, this causes the launcher application to exit; to quit a C++ application when this method is called, connect the QQmlEngine::quit() signal to the QCoreApplication::quit() slot.
exit(1) should do the job. Calling exit is basically pulling the power plug and killing the application. That is certainly a way, but not always desirable. You may declare a signal in your main window and connect the signal to quit before you call exec().
To complete the discussion in the comments for others who came here: This functionality has been added to Qt by the OP in this change to Qt. Having a look at the documentation of Qt 5.7 and Qt 5.8, one can see that this change was not in 5.7 but has made it into the 5.8 release here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With