Thanks but actually, when I remove the code and let the default behavior happen, it still fails to close. I even experimented with a two line application:
int main (int argc, char** argv) {
return app.exec();
}
int main (int argc, char** argv) {
QApplication app(argc, argv);
return app.exec();
}
To copy to clipboard, switch view to plain text mode
and that will tell the system not to shut down.
I started to look at the delegate. Is it at possible that this code from qcocooaapplicationdelegate_mac.mm is causing it to return with a NSTerminateCancel which stops the shutdown? Would a terminate from the mac system go through this code?
// This function will only be called when NSApp is actually running. Before
// that, the kAEQuitApplication apple event will be sendt to
// QApplicationPrivate::globalAppleEventProcessor in qapplication_mac.mm
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
Q_UNUSED(sender);
// The reflection delegate gets precedence
if (reflectionDelegate
&& [reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)]) {
return [reflectionDelegate applicationShouldTerminate:sender];
}
if (qtPrivate->canQuit()) {
if (!startedQuit) {
startedQuit = true;
qAppInstance()->quit();
startedQuit = false;
}
}
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;
}
}
// This function will only be called when NSApp is actually running. Before
// that, the kAEQuitApplication apple event will be sendt to
// QApplicationPrivate::globalAppleEventProcessor in qapplication_mac.mm
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
Q_UNUSED(sender);
// The reflection delegate gets precedence
if (reflectionDelegate
&& [reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)]) {
return [reflectionDelegate applicationShouldTerminate:sender];
}
if (qtPrivate->canQuit()) {
if (!startedQuit) {
startedQuit = true;
qAppInstance()->quit();
startedQuit = false;
}
}
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;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks