views:

65

answers:

2

Hi,

I have a Qt 4.6.2 application, running on a Windows XP SP2 x64 system.

When I press the physical power/shutdown button on the system, when my application is running nothing will happen, the app will not close and the system does not Shutdown.

If I go to start menu and click shutdown, then my application will close but the system will not shutdown.

With my app closed the system shuts down fine in both ways.

Any ideas what I can do to get my application to behave and allow the system to shutdown correctly?

Thanks, Zac

+1  A: 

You need to reimplement QCoreApplication::winEventFilter in your QCoreApplication / QApplication derived class, and handle the WM_QUERYENDSESSION message there.

I'm not sure whether WM_QUERYENDSESSION will be delivered to your application or whether it's a broadcast system message (and I don't have a Windows machine handy to test.) If you don't seem to receive this message there, you'll need to install an event filter.

In either case, you need to properly respond to WM_QUERYENDSESSION - that's the message you need to handle.

Mihai Limbășan
A: 

Read aboout QSessionManager and QApplication::commitData - it's more Qt way

Kamil Klimek