View Full Version : Shutdown on Mac failing

10th December 2010, 23:09

I am using qt 4.6.3 on mac.

When I run my application and the user does a system shutdown. Somewhere in my app, the shutdown is intercepted and the shutdown canceled. I have made sure that none of the closeEvent accept the event. I also have my own QApplication and have connected commitDataRequest to slot (which is never getting called) and reimplemented commitData which is also never getting called.

It looks like something much earlier stops it from happening. Has anyone experienced this?


11th December 2010, 00:15
I have made sure that none of the closeEvent accept the event.
And that's exactly what prevents your system from shutting down.

11th December 2010, 01:19
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) {
QApplication app(argc, argv);
return app.exec();

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)applicationShouldTerm inate:(NSApplication *)sender
// The reflection delegate gets precedence
if (reflectionDelegate
&& [reflectionDelegate respondsToSelector:@selector(applicationShouldTerm inate:)]) {
return [reflectionDelegate applicationShouldTerminate:sender];

if (qtPrivate->canQuit()) {
if (!startedQuit) {
startedQuit = true;
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;

11th December 2010, 01:28
How do you know it is your application that is preventing the shutdown? Do any other Qt applications behave that way?

11th December 2010, 02:41
When I don't run my application, the system shuts down. When I ran that application that I included, the system did not shutdown either. (And the mac message dialog tells me that it is the application that is stopping it from shutting down). The application itself does exit (both mine and that one).