tags:

views:

67

answers:

2

Hello All,

I need a event handler when ever shutdown message is send to system. Can anyone help?

When ever we try to shutdown a system, and if any dialog box is open shutdown process terminates. I don't want this to happen in my application. i.e if any dialog box is open from my application and I try to shutdown my system then it should not block shutdown process. Is this implementation possible?

Thanks, Rahul

A: 

Yes, look at NSWorkspaceWillPowerOffNotification

http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html

Ken Aspeslagh
I cannot use cocoa.
Rahul
A: 

try overriding QApplication::commitData it should be called whenever user shuts down the system and your application is still running.

This function deals with session management. It is invoked when the QSessionManager wants the application to commit all its data.

Usually this means saving all open files, after getting permission from the user. Furthermore you may want to provide a means by which the user can cancel the shutdown.

below is an example (never tried it with macs; though works fine on my ubuntu):

main.cpp:

#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QSessionManager>

class MyApplication : public QApplication
{
public:
    MyApplication(int &argc, char **argv);
    virtual void commitData(QSessionManager& sm);
};

MyApplication::MyApplication(int &argc, char **argv):
        QApplication(argc, argv)
{
    //???
}

void MyApplication::commitData(QSessionManager& sm)
{
    // do smth here....    
    QApplication::commitData(sm);
}

int main(int argc, char *argv[])
{
    MyApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

hope this helps, regards

serge_gubenko
Sorry, same sample I copied on Mac, it doesn't work.
Rahul