确定连接到 Qt 中给定槽的信号 [英] Determine signals connected to a given slot in Qt

查看:34
本文介绍了确定连接到 Qt 中给定槽的信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将自己注入到一个 Qt 应用程序中,我试图找出给定插槽连接到哪些信号,但找不到任何有关执行此操作的信息.是否有一种开箱即用的机制?如果是这样,这是否暴露于 QtScript?(如果没有,我可以很容易地包装它.)

I've injected myself into a Qt application, and I'm attempting to figure out what signals a given slot is connected to, but can't find any information on doing this. Is there a mechanism for doing this out of the box? If so, is this exposed to QtScript? (If not, I can wrap it easily enough.)

如果没有这种机制,添加它的最佳方法是什么?我不能在简单的挂钩之外操作现有的应用程序,但我可以挂钩 QObject::connect 并自己存储连接,只是不确定这是否是最好的方法.

If there is no such mechanism, what would be the best way to add it? I cannot manipulate the existing application outside of simple hooking, but I could hook QObject::connect and store the connections myself, just not sure if that's the best way to go about it.

推荐答案

在研究 Qt 代码库和文档后(我从这里和其他地方得到了很多有用的提示),我最终决定挂钩 QObject::connect(静态过载).为什么?好吧,其他解决方案要求您知道哪些对象正在提供信号,深入研究私有字段,或者必须具有 Qt 的调试版本.最后,挂钩 QObject::connect 为您提供了应用程序中连接的所有内容,并且您可以轻松地映射回插槽.

After digging around in the Qt code base and documentation (I got lots of helpful tips from here and elsewhere), I ended up settling on hooking QObject::connect (the static overload). Why? Well, the other solutions require you to know what objects are providing the signals, dig into private fields, or have to have a debug build of Qt. In the end, hooking QObject::connect gives you everything connected in the application, and you can trivially map back to the slots.

这篇关于确定连接到 Qt 中给定槽的信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆