Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exit with a return code from QML

Tags:

qt

qml

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).

like image 802
cavitsinadogru Avatar asked Dec 17 '15 08:12

cavitsinadogru


People also ask

How do I close a QML application?

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.

How do you exit a program in Qt?

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().


1 Answers

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.

like image 85
FourtyTwo Avatar answered Sep 23 '22 18:09

FourtyTwo