PDA

View Full Version : NSWorkspaceWillPowerOffNotification not working with Qt Cocoa Mac Application



jainishjain
7th April 2011, 16:40
Hi,

I am working on Mac application using Qt Cocoa. I want to track log out/shut down event. I looked at Qt for some solution however it seems to be more at OS level so Qt doesn't provide anything.

So I switched to NSWorkspace and registered to get Sleep (NSWorkspaceWillSleepNotification) and Log out (NSWorkspaceWillPowerOffNotification). I am able to get Sleep notification but not able to get Log Out/shut down notifications in Qt App.

To verify registration code, I created a simple Cocoa application and both sleep and log out notification works in this case.

Below is the code which works with cocoa application (receiveLogOutShutDownNote gets called) and not with Qt App.

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
selector: @selector(receiveLogOutShutDownNote:)
name: NSWorkspaceWillPowerOffNotification object: NULL];
- (void) receiveLogOutShutDownNote: (NSNotification*) note
{
NSLog(@"receiveLogOutShutDownNote: %@", [note name]);
}

Please help me to figure out what is the difference between two.

Jainish