连接到 QtScript(在 Qt 4.5.2 上)中的信号的函数不会触发
我已经注入了专有的 Qt (4.5.2) 应用程序,添加了我自己的 QtScript 兼容版本,并设法访问了我需要的所有信号。但是,当连接到它们时(通过 QtScript)我的函数永远不会被调用。
我提出了一些理论来解释为什么会这样,并且我已经测试了我能想到的一切,但我遇到了一些困难。请注意,我从未遇到过任何连接异常。这是我当前的理论:
- 我连接到的信号已经连接到其他插槽,这在某种程度上阻止了它(但据我所知,所有 Qt 信号都会在没有额外工作的情况下触发到所有插槽,并且不能被以这种方式限制)
- 信号拒绝我的连接,或者在连接后断开我的连接(但我看不到这方面的设施)
- 我的连接是从另一个线程发生的,这在某种程度上导致它无法正确连接
这些理论中的任何一个都是合理的?如果没有,我错过了什么?
I've injected into a proprietary Qt (4.5.2) application, added my own compatible build of QtScript, and have managed to get access to all the signals I need. However, when connecting to them (via QtScript) my functions are never called.
I've come up with a few theories for why this is and I've tested everything I can think of, but I've hit a bit of a wall. Note, I've never had any connection exceptions whatsoever. Here are my current theories:
- The signals I'm connecting to are already connected to other slots, and that's somehow blocking it (but as far as I know, all Qt signals fire to all slots with no extra work, and can't be restricted in this way)
- The signals are rejecting my connection, or disconnecting me after connection (but I see no facility for this)
- My connection is happening from another thread, and this is somehow causing it not to connect properly
Are any of these theories plausible? If not, what have I missed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过大量挖掘内部结构并提出很多问题(即此处和 Freenode 上的 #qt 中),我设法让它工作。问题是我注入的代码在没有事件泵的本机线程中运行。实例化 QEventLoop 并定期调用 processEvents() 解决了这个问题。
After a whole lot of digging around internals and asking a lot of questions (here and in #qt on Freenode, namely), I managed to get it to work. The problem was that my injected code ran in a native thread without an event pump. Instantiating QEventLoop and calling processEvents() at regular intervals solved this.
这个问题确实很古老并且已经得到解答,但是对于那些来这里寻求帮助并且上述方法不是一个好的解决方案的人来说,您可能需要考虑在 connect 语句中设置 Qt::ConnectionType到Qt::DirectConnection,如下所示:
这应该以不同的方式解决相同的问题。
This question is really old and already answered but for those that come here looking for help and for who the above is not a good solution, you might want to consider setting the Qt::ConnectionType in the connect statement to Qt::DirectConnection like so:
Which should solve the same problem in a different way.