求助,怎么我的头文件和其他版本不同呢?

cdwolf3 2014-07-28 03:23:10
我是QT初学者, 现在要重写子类重写 QCoreApplication::winEventFilter(message,result),但是发现QCoreApplication.h里没有winEventFilter这个函数,但是我在网上看的demo里都有,百思不得其解啊。。。。
还有就是使用 MSG *message; switch(message->message);就报下面的错,简直无语了:
error: invalid use of incomplete type 'MSG {aka struct tagMSG}'
switch(message->message)
...全文
879 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
dbzhang800 2014-08-01
  • 打赏
  • 举报
回复
引用 17 楼 cdwolf3 的回复:
[quote=引用 16 楼 dbzhang800 的回复:] [quote=引用 15 楼 cdwolf3 的回复:] 是的,现在要修改一个控制台程序,需要捕捉WM_CLOSE消息,让它点击右上角的X时最小化到系统托盘区。
其实我真正想说的是:控制台程序哪儿来的WM_CLOSE消息?[/quote] 小弟初学。。。那应该捕捉什么消息,才能让它最小化而不是关闭?[/quote] 只能说,所有的GUI特有的消息对Console程序来说,全都没用。 Windows系统相关的东西,多看看MSDN吧 http://msdn.microsoft.com/en-us/library/windows/desktop/ms686016%28v=vs.85%29.aspx
cdwolf3 2014-08-01
  • 打赏
  • 举报
回复
引用 16 楼 dbzhang800 的回复:
[quote=引用 15 楼 cdwolf3 的回复:] 是的,现在要修改一个控制台程序,需要捕捉WM_CLOSE消息,让它点击右上角的X时最小化到系统托盘区。
其实我真正想说的是:控制台程序哪儿来的WM_CLOSE消息?[/quote] 小弟初学。。。那应该捕捉什么消息,才能让它最小化而不是关闭?
dbzhang800 2014-08-01
  • 打赏
  • 举报
回复
引用 15 楼 cdwolf3 的回复:
是的,现在要修改一个控制台程序,需要捕捉WM_CLOSE消息,让它点击右上角的X时最小化到系统托盘区。
其实我真正想说的是:控制台程序哪儿来的WM_CLOSE消息?
cdwolf3 2014-08-01
  • 打赏
  • 举报
回复
引用 14 楼 dbzhang800 的回复:
[quote=引用 13 楼 cdwolf3 的回复:] 还是不懂。。。完全捕捉不了WM_COLSE事件
从你前面的代码看,你的程序是控制台程序,而非GUI程序。不知道你的真实代码是否也是如此?[/quote] 是的,现在要修改一个控制台程序,需要捕捉WM_CLOSE消息,让它点击右上角的X时最小化到系统托盘区。
dbzhang800 2014-08-01
  • 打赏
  • 举报
回复
引用 13 楼 cdwolf3 的回复:
还是不懂。。。完全捕捉不了WM_COLSE事件
从你前面的代码看,你的程序是控制台程序,而非GUI程序。不知道你的真实代码是否也是如此?
cdwolf3 2014-08-01
  • 打赏
  • 举报
回复
还是不懂。。。完全捕捉不了WM_COLSE事件
powerwheel 2014-07-31
  • 打赏
  • 举报
回复
windows_generic_MSG 这个是windows的MSG结构体你上面的代码不是都有吗 MSG *message; switch(message->message);就报下面的错,简直无语了: error: invalid use of incomplete type 'MSG {aka struct tagMSG}' switch(message->message) 头文件肯定就是windows.h了
powerwheel 2014-07-30
  • 打赏
  • 举报
回复
On Windows, eventType is set to "windows_generic_MSG" for messages sent to toplevel windows, and "windows_dispatcher_MSG" for system-wide messages such as messages from a registered hot key. In both cases, the message can be casted to a MSG pointer. The result pointer is only used on Windows, and corresponds to the LRESULT pointer. 在windows上面有两个windows_generic_MSG与windows_dispatcher_MSG,你看下需要哪个用哪一个就行了。
cdwolf3 2014-07-30
  • 打赏
  • 举报
回复
//---------------------------------------自定义tNativeEventFilter-------------------------------------------------// class MyNativeEventFilter: public QAbstractNativeEventFilter { public: //MyNativeEventFilter(); virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *)Q_DECL_OVERRIDE; }; bool MyNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *) { if (eventType == "windows_generic_MSG") { //windows_generic_MSG* ev = static_cast<windows_generic_MSG *>(message); } return false; } //---------------------------------------自定义tNativeEventFilter End-------------------------------------------------// int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); MyNativeEventFilter *NewFilter = new MyNativeEventFilter; a.installNativeEventFilter(NewFilter); return a.exec(); } 为什么 我照着楼上的列子写了后,根本不能执行到我定义的nativeEventFilter里呢?
cdwolf3 2014-07-30
  • 打赏
  • 举报
回复
引用 9 楼 powerwheel 的回复:
我在linux下测试是正常的,在windows下用这个做过全局快捷键
windows_generic_MSG 这个要什么头文件。。。找遍帮助文档和网上都没找到。。。。
cdwolf3 2014-07-30
  • 打赏
  • 举报
回复
引用 9 楼 powerwheel 的回复:
我在linux下测试是正常的,在windows下用这个做过全局快捷键
谢谢,现在程序启动的时候可以到我定义的nativeEventFilter函数了,但是不响应我对控制台窗体的操作呢? 我需要重写控制台的关闭事件,就是重写WM_CLOSE或者WM_QUIT消息,让它关闭的时候最小化。。。
powerwheel 2014-07-30
  • 打赏
  • 举报
回复
我在linux下测试是正常的,在windows下用这个做过全局快捷键
powerwheel 2014-07-28
  • 打赏
  • 举报
回复
可以用这个的 void QCoreApplication::installNativeEventFilter(QAbstractNativeEventFilter * filterObj) bool QAbstractNativeEventFilter::nativeEventFilter(const QByteArray & eventType, void * message, long * result) [pure virtual] This method is called for every native event. Note: The filter function here receives native messages, for example, MSG or XCB event structs. It is called by the QPA platform plugin. On Windows, it is called by the event dispatcher. The type of event eventType is specific to the platform plugin chosen at run-time, and can be used to cast message to the right type. On X11, eventType is set to "xcb_generic_event_t", and the message can be casted to a xcb_generic_event_t pointer. On Windows, eventType is set to "windows_generic_MSG" for messages sent to toplevel windows, and "windows_dispatcher_MSG" for system-wide messages such as messages from a registered hot key. In both cases, the message can be casted to a MSG pointer. The result pointer is only used on Windows, and corresponds to the LRESULT pointer. On Mac, eventType is set to "mac_generic_NSEvent", and the message can be casted to an EventRef. On Blackberry (not plain QNX) eventType is set to "bps_event_t", and the message can be casted to a bps_event_t pointer. In your reimplementation of this function, if you want to filter the message out, i.e. stop it being handled further, return true; otherwise return false. Example: class MyXcbEventFilter : public QAbstractNativeEventFilter { public: virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *) Q_DECL_OVERRIDE { if (eventType == "xcb_generic_event_t") { xcb_generic_event_t* ev = static_cast<xcb_generic_event_t *>(message); // ... } return false; } };
dbzhang800 2014-07-28
  • 打赏
  • 举报
回复
引用 4 楼 cdwolf3 的回复:
我在QT5.3.1的帮助文档中又没发现QCoreApplication 舍弃了winEventFilter函数,算了还是下个QT4算了
Qt5文档中有一个专门的页面叫做: C++ API changes
cdwolf3 2014-07-28
  • 打赏
  • 举报
回复
我在QT5.3.1的帮助文档中又没发现QCoreApplication 舍弃了winEventFilter函数,算了还是下个QT4算了
彩阳 2014-07-28
  • 打赏
  • 举报
回复
网上的例子还都是Qt4的,要注意喽。
dbzhang800 2014-07-28
  • 打赏
  • 举报
回复
Qt5 需要看Qt5的手册,你看Qt4的手册或例子是不行的。
cdwolf3 2014-07-28
  • 打赏
  • 举报
回复
我的环境是QT5.3.1;

16,819

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧