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>
This commit is contained in:
parent
f2b802f923
commit
43f2d43e8f
@ -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]
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user