diff options
author | d3fault <d3fault@d3fault.net> | 2017-12-03 11:41:22 -0700 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2018-01-09 13:21:21 +0000 |
commit | 43f2d43e8f42446985fe7e5e56c85ebd2812d5ab (patch) | |
tree | 40e36f748ffc1a10b5f12951b234360b3677fc99 /src | |
parent | f2b802f9232c078ec83a1cb71385efcef8db32db (diff) |
Add doc explaining the gotcha when connecting a signal to qApp->exit
Change-Id: I981e4bfdf679bf755665748e9d3b389a94561e55
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Martin Smith <martin.smith@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 14 |
2 files changed, 15 insertions, 1 deletions
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 |