Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to hook the Mac dock menu "quit" action in 4.7.2?
rushmanbert last edited by
I have found posts that hint at the information I need, but none of them have come through so far.
I am using Qt 4.7.2 and cannot change to anything newer.
My app makes these calls:
and everything works beautifully except that if I right click on the dock item for the app and click on "quit" my app just quits with a return value of zero without posting any events that tell me it's quitting. At the time of the quit, I have a session open with a server that I would really like to close before the app exits. The current behavior doesn't let me do that.
I have derived my own application class from QApplication and overridden the notify() method (among others). I eventually had it display the event type to stdout on every call so I could see the event stream.
If I do NOT make this call:
then when I click quit in the dock menu I receive a QEvent::Close event type, which I can act on appropriately and do an orderly shutdown on the app. If I DO make that call (and I must make it because of the type of app it is) then I do not receive a Close event at all, nor any other event that hints at what is happening. I added a call to QApplication::closingDown() in my notify() method, but that never returns true either.
I found a post about not seeing the dock quit that said there was a bug introduced in Qt 4.6. The workaround was to do this:
long refCon = 0;
AEEventHandlerUPP handler = NULL;
AEGetEventHandler(kCoreEventClass, kAEQuitApplication, &handler, &refCon, false);
int argc = 0;
(void)new QApplication(argc, 0, true);
AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, handler, refCon, false);
which I tried. The code would not compile as shown, but I managed to pass the address of an array of pointers as the "&refCon" argument and the compiler was happy (and put some pointers into the array). But the handler value remained NULL after the call, so nothing happened after the QApplication was created.
The difference here seems to be whether the AA_MacPluginApplication attribute has been set, but maybe I'm doing something else wrong.
Any suggestions would be welcome.
Hi and welcome to devnet,
If I followed you correctly what you would need to use is the commitData function of QApplication or a connection to commitDataRequest.
However, with a big H, they are not called on OS X (it's part of the "session management")
It's currently a work in progress for Qt 5 and should be back ported to Qt 4.8