继承Qt的基类QAbstractNativeEventFilter
class HHNativeEventFilter : public QAbstractNativeEventFilter
{
protected:
bool nativeEventFilter(const QByteArray &eventType, void *message, long *)
{
if (eventType == "windows_generic_MSG"
|| eventType == "windows_dispatcher_MSG")
{
PMSG msg = static_cast<PMSG>(message);
if(msg->message == WM_CLOSE )
{
qApp->exit();
}
}
return false;
}
};
利用QApplication注册类对象
app.installNativeEventFilter(new NativeEventFilter);