From 552a1f1942ac5a004e54bad2f1048ce220a3156d Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 20 Aug 2009 15:40:31 +0200 Subject: Cocoa: cannot quit application If Qt is used from within a native cocoa application. This patch allowes the application to terminate if we have no current event loops running. This should be safe in itself, and also handle the case where NSApp run is called from outside Qt. Task-number: 259928 Reviewed-by: msorvig --- src/gui/kernel/qcocoaapplicationdelegate_mac.mm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm index 572df70..172d07b 100644 --- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm +++ b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm @@ -197,11 +197,19 @@ static void cleanupCocoaApplicationDelegate() } } - // Prevent Cocoa from terminating the application, since this simply - // exits the program whithout allowing QApplication::exec() to return. - // The call to QApplication::quit() above will instead quit the - // application from the Qt side. - return NSTerminateCancel; + if (qtPrivate->threadData->eventLoops.size() == 0) { + // INVARIANT: No event loop is executing. This probably + // means that Qt is used as a plugin, or as a part of a native + // Cocoa application. In any case it should be fine to + // terminate now: + return NSTerminateNow; + } else { + // Prevent Cocoa from terminating the application, since this simply + // exits the program whithout allowing QApplication::exec() to return. + // The call to QApplication::quit() above will instead quit the + // application from the Qt side. + return NSTerminateCancel; + } } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification -- cgit v0.12