What is the difference between the quit and Exit methods of qApp?

Asked

Viewed 115 times

3

I’m testing the example Getting Started Programming with Qt Widgets and found a call for a method to exit the application:

void Notepad::on_quitButton_clicked()
{
    qApp->quit();
}

I took a look at the other methods and found one that apparently does the same thing:

qApp->exit();

What is the difference between these two methods and when I should use one or the other?

1 answer

2

The variable qApp is a global pointer that refers to the single object application. It is equivalent to the pointer returned by the function QCoreApplication::instance(), except that, in GUI applications, it is a pointer to an instance of QApplication. http://doc.qt.io/qt-4.8/qapplication.html#qApp

Being qApp an instance of QCoreApplication, one of the differences is that the method quit is a SLOT, that is, it can be used in response to a Qt signal.

Signals & Slots

Another difference between the methods is that the quit always returns 0 (zero), while the method exit can receive an integer number to return a different code.

void Qcoreapplication::quit()

void Qcoreapplication::Exit(int returnCode = 0)

That is, both methods should be used when the application should be closed, but the quit, which does not allow error code assignment, can be used directly in connection with a signal, and the exit, which allows error code assignment, can only be used in the conventional way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.