diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp index 7d4d5f2a8d..aae2456bf1 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp @@ -56,7 +56,7 @@ QApplication::sendEvent(mainWindow, &event); //! [1] QPushButton *quitButton = new QPushButton("Quit"); -connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit())); +connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()), Qt::QueuedConnection); //! [1] diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 38bcba275f..7c39910212 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1370,6 +1370,13 @@ void QCoreApplicationPrivate::execCleanup() By convention, a \a returnCode of 0 means success, and any non-zero value indicates an error. + It's good practice to always connect signals to this slot using a + \l{Qt::}{QueuedConnection}. If a signal connected (non-queued) to this slot + is emitted before control enters the main event loop (such as before + "int main" calls \l{QCoreApplication::}{exec()}), the slot has no effect + and the application never exits. Using a queued connection ensures that the + slot will not be invoked until after control enters the main event loop. + Note that unlike the C library function of the same name, this function \e does return to the caller -- it is event processing that stops. @@ -1898,6 +1905,13 @@ void QCoreApplicationPrivate::maybeQuit() to quit(), and you also often connect e.g. QAbstractButton::clicked() or signals in QAction, QMenu, or QMenuBar to it. + It's good practice to always connect signals to this slot using a + \l{Qt::}{QueuedConnection}. If a signal connected (non-queued) to this slot + is emitted before control enters the main event loop (such as before + "int main" calls \l{QCoreApplication::}{exec()}), the slot has no effect + and the application never exits. Using a queued connection ensures that the + slot will not be invoked until after control enters the main event loop. + Example: \snippet code/src_corelib_kernel_qcoreapplication.cpp 1