如何调试 Qt 中非 GUI 线程发布的丢失事件?
正如主题所说,我正在从非 GUI 线程(准确地说是一些 GStreamer 线程)发布事件。代码如下所示:
GstBusSyncReply on_bus_message(GstBus* bus, GstMessage* message, gpointer data)
{
bool ret = QMetaObject::invokeMethod(static_cast<QObject*>(data), "stateChanged", Qt::QueuedConnection);
Q_ASSERT(ret);
return GST_BUS_PASS;
}
问题是,stateChanged
(无论是槽还是信号)没有被调用。我已经使用调试器进入了QMetaObject::invokeMethod
,跟踪它直到它调用PostMessage
(顺便说一句,它是 Windows 上的 Qt 4.6.2)——一切似乎都正常没事。
data
指向的对象存在于 GUI 线程中,我已经仔细检查过这一点。
我该如何调试这个问题?或者,更好的是,也许完全回避它?
As the subject says, I'm posting events from non-GUI thread (some GStreamer thread, to be precise). Code looks like this:
GstBusSyncReply on_bus_message(GstBus* bus, GstMessage* message, gpointer data)
{
bool ret = QMetaObject::invokeMethod(static_cast<QObject*>(data), "stateChanged", Qt::QueuedConnection);
Q_ASSERT(ret);
return GST_BUS_PASS;
}
The problem is, stateChanged
(doesn't matter whether it is a slot or signal) is not called. I've stepped into QMetaObject::invokeMethod
with debugger, followed it till it called PostMessage
(it is Qt 4.6.2 on Windows, by the way) – everything seemed to be OK.
Object pointed to by data
lives in GUI thread, I've double-checked this.
How can I debug this problem? Or, better, maybe sidestep it altogether?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
0小时我的上帝。
我太傻了。
我实际上花了天来调试这个。
问题如下:
是的,我重新实现了 QObject::event()(为显示/隐藏和调整大小事件添加一些特殊处理),并且没有调用基类方法。而且,猜猜看,
Qt::QueuedConnection
使用QEvent
进行延迟调用。永远不要做像我一样的事情。真的。
或者,亲爱的 Qt,您可以使用 NVI 来保护我们吗反对这种错误?
0h my god.
I am so stupid.
I've spent literally days debugging this.
And the problem looked like this:
Yes, I've reimplemented
QObject::event()
(to add some special processing for show/hide and resize events), and did not call the base method. And, guess what,Qt::QueuedConnection
usesQEvent
s to make the deferred calls.Never do things like I did. Really.
Or, dear Qt, can you please use NVI to guard us against this sort of mistakes?