I am trying to implement winEventFilter in my QT application using QT Creator, QT SDK and Windows APIs
Declared the below in my class file
bool winEventFilter( MSG * msg, long * result )
{
if( msg->message == WM_QUERYENDSESSION)
DebugLog("shutdown");
else
DebugLog("Quit") ;
}
I am calling the above method in the following way
MSG * msg;
long * result;
winEventFilter(msg, result);
When I logoff or shutting down my computer it never prints the log shutdown
The condition
msg->message == WM_QUERYENDSESSIONwill never be true, since you’re calling the function with an unitialized pointer (MSG * msg).You need to pass a meaningful
msg.However, this is not how you want to implement winEventFilter.
winEventFilteris a method ofQCoreApplicationthat you should use by reimplementing it in yourQCoreApplicationsubclass. Then it will be called automatically for you.See http://qt-project.org/doc/qt-4.8/qcoreapplication.html#winEventFilter for more details.