admin 管理员组文章数量: 1184232
介绍Qt4和Qt5获取Windows系统事件的方法。
Qt4版本的实现
方法1:
- 通过继承QWidget的类中重新实现winEvent接口,以接收在消息参数中传递的本机Windows事件。
bool QWidget::winEvent(MSG *message, long *result)
方法2:
- 通过继承QCoreApplication的类中重新实现winEventFilter接口,以接收在消息参数中传递的本机Windows事件。
bool QCoreApplication::winEventFilter(MSG *msg, long *result)
Qt5版本实现
方法1:
- 通过继承QWidget的类中重新实现winEvent接口,以接收在消息参数中传递的eventType标识的本机平台事件。
bool QWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
方法2:
- 通过继承QAbstractNativeEventFilter的类中重新实现nativeEventFilter接口:
bool QAbstractNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
并安装到中:
void QCoreApplication::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
或安装到:
void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
- 特别地:不同平台对应的eventType类型有:
| 平台 | 事件类型(eventType) | 消息类型(message) | 结果类型(result) |
|---|---|---|---|
| Windows | “windows_generic_MSG” | MSG * | LRESULT |
| macOs | “NSEvent” | NSEvent * | 无 |
| XCB(Linux) | “xcb_generic_event_t” | xcb_generic_event_t * | 无 |
版权声明:本文标题:使用Qt接口获取Windows系统的事件 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1767484186a3474640.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论