diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 8f56001604..adefea4f09 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1260,18 +1260,30 @@ int QCoreApplication::exec() self->d_func()->aboutToQuitEmitted = false; int returnCode = eventLoop.exec(); threadData->quitNow = false; - if (self) { - self->d_func()->in_exec = false; - if (!self->d_func()->aboutToQuitEmitted) - emit self->aboutToQuit(QPrivateSignal()); - self->d_func()->aboutToQuitEmitted = true; - sendPostedEvents(0, QEvent::DeferredDelete); - } + + if (self) + self->d_func()->execCleanup(); return returnCode; } +// Cleanup after eventLoop is done executing in QCoreApplication::exec(). +// This is for use cases in which QCoreApplication is instantiated by a +// library and not by an application executable, for example, Active X +// servers. + +void QCoreApplicationPrivate::execCleanup() +{ + threadData->quitNow = false; + in_exec = false; + if (!aboutToQuitEmitted) + emit q_func()->aboutToQuit(QCoreApplication::QPrivateSignal()); + aboutToQuitEmitted = true; + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); +} + + /*! Tells the application to exit with a return code. diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h index 445bae01b4..3601add098 100644 --- a/src/corelib/kernel/qcoreapplication_p.h +++ b/src/corelib/kernel/qcoreapplication_p.h @@ -145,6 +145,8 @@ public: static inline void clearApplicationFilePath() { delete cachedApplicationFilePath; cachedApplicationFilePath = 0; } #ifndef QT_NO_QOBJECT + void execCleanup(); + bool in_exec; bool aboutToQuitEmitted; bool threadData_clean;