In my Qt app, I have a quit routine which gracefully cleans up everything before finally quitting, else there might be a crash somewhere. The app runs in the system tray, and there is a "Quit" menu defined for the system tray icon. On the quitAction I have set the menu role so that it's merged with Mac's app menu, but I don't see my slot being called. The code is below:
QAction *quitAction = new QAction(tr("&Quit"), this);
quitAction->setMenuRole(QAction::QuitRole);
connect(quitAction, SIGNAL(triggered()), this, SLOT(quittingApp()));
I have also tried to capture the QCloseEvent on QApplication but even that doesn't seem to work.
bool MyApplication::event(QEvent *ev)
{
bool eaten = false;
switch (ev->type())
{
case QEvent::Close:
{
quittingApp(); //My quit cleanup routine
eaten = true;
break;
}
default:
eaten = QApplication::event(ev);
break;
}
return eaten;
}
Am I missing something here? What's the best way to have my own cleanup routine which is called during quit?