What is the difference between the qApp quit and exit methods?

3

I'm testing the example Getting Started Programming with Qt Widgets and found a call from a method to exit 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 should I use one or the other?

    
asked by anonymous 03.06.2015 / 17:45

1 answer

2
  

The variable qApp is a global pointer that refers to the single object   application. Equivalent to the pointer returned by the function    QCoreApplication::instance() , except that in GUI applications, it is a   pointer to an instance of QApplication .    link

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

Signals & Slots

Another difference between methods is that the SLOT always returns 0 (zero), whereas the quit method can receive an integer 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 exit , which does not allow error code assignment, can be used directly in connection with a signal, and quit which allows error code assignment, can only be used in the conventional way.

    
03.06.2015 / 17:45