如何调试QMetaObject::invokeMethod函数?

小鸟向前飞 2015-08-10 10:56:42
代码在执行


QMetaObject::invokeMethod(m_manager, "onEventRequest", Qt::QueuedConnection, Q_ARG(int, 0));


时没有执行对应的onEventRequest函数,想问一下如何调试invokeMethod函数?想知道为什么没有执行对应函数的原因.
由于其他代码比较长也挺复杂 就不贴上来了
...全文
607 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
小鸟向前飞 2015-08-21
  • 打赏
  • 举报
回复
已解决 是QApplication为空的导致消息消息循环阻塞
wafstudio 2015-08-14
  • 打赏
  • 举报
回复
引用 6 楼 keke_zkt 的回复:
[quote=引用 5 楼 wafstudio 的回复:] [quote=引用 4 楼 keke_zkt 的回复:] 由于slots是public的 我可以直接以m_manager->onEventRequest(0)的方式调用 来测试吗? invokeMethod是等价的吗?
是的,可以直接调用,就像普通函数一样。 区别就是invokeMethod可以指定槽函数的调用时机。[/quote] 这个调用时机该怎么理解? 我猜测m_manager没有调到onEventRequest可能是收到一些因素的影响。 有没有其他的函数设定invokemthod调用slot的条件?[/quote] The invocation can be either synchronous or asynchronous, depending on type: If type is Qt::DirectConnection, the member will be invoked immediately. If type is Qt::QueuedConnection, a QEvent will be sent and the member is invoked as soon as the application enters the main event loop. If type is Qt::BlockingQueuedConnection, the method will be invoked in the same way as for Qt::QueuedConnection, except that the current thread will block until the event is delivered. Using this connection type to communicate between objects in the same thread will lead to deadlocks. If type is Qt::AutoConnection, the member is invoked synchronously if obj lives in the same thread as the caller; otherwise it will invoke the member asynchronously. 调试模式一步步跟踪代码,进入Qt的源代码中查找原因。
小鸟向前飞 2015-08-13
  • 打赏
  • 举报
回复
引用 5 楼 wafstudio 的回复:
[quote=引用 4 楼 keke_zkt 的回复:] 由于slots是public的 我可以直接以m_manager->onEventRequest(0)的方式调用 来测试吗? invokeMethod是等价的吗?
是的,可以直接调用,就像普通函数一样。 区别就是invokeMethod可以指定槽函数的调用时机。[/quote] 这个调用时机该怎么理解? 我猜测m_manager没有调到onEventRequest可能是收到一些因素的影响。 有没有其他的函数设定invokemthod调用slot的条件?
wafstudio 2015-08-11
  • 打赏
  • 举报
回复
引用 4 楼 keke_zkt 的回复:
由于slots是public的 我可以直接以m_manager->onEventRequest(0)的方式调用 来测试吗? invokeMethod是等价的吗?
是的,可以直接调用,就像普通函数一样。 区别就是invokeMethod可以指定槽函数的调用时机。
小鸟向前飞 2015-08-11
  • 打赏
  • 举报
回复
由于slots是public的 我可以直接以m_manager->onEventRequest(0)的方式调用 来测试吗? invokeMethod是等价的吗?
小鸟向前飞 2015-08-11
  • 打赏
  • 举报
回复
引用 1 楼 wafstudio 的回复:
1、invokeMethod的返回值是什么,true代表调用成功了,false代表失败,失败的原因可能是:函数不存在或参数不匹配; 2、你将Qt::QueuedConnection换成Qt::DirectConnection试试。
返回值是true, 但是我在onEventRequest这个函数里加qdebug, 在控制台没有输出qdebug信息,在函数开始处加断点也走不到
wafstudio 2015-08-10
  • 打赏
  • 举报
回复
1、invokeMethod的返回值是什么,true代表调用成功了,false代表失败,失败的原因可能是:函数不存在或参数不匹配; 2、你将Qt::QueuedConnection换成Qt::DirectConnection试试。
astro_lee 2015-08-10
  • 打赏
  • 举报
回复
一般没有调用成功,Qt会在控制台输出调试信息,楼主可以看看。

16,202

社区成员

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

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