Qt 从小部件获取信号槽连接信息

发布于 2024-11-26 10:44:35 字数 241 浏览 1 评论 0原文

我感觉当前的 API 不可能做到这一点,但我必须问一下。是否可以查询特定 QObject 的信号或插槽名称(从元对象)并检索所有 QObject 及其连接到它的插槽或信号名称?

我这样做是因为,实际上,我有大量的布局,其中包含相同的小部件排列,每个布局都有一个对象,并且每个布局的小部件控制它的各种属性。我想保留一种布局,并将其小部件的信号/槽以相同的模式连接到所有其他对象,但为了做到这一点,我需要“记录”所有信号槽数据。

是否可以?

I have a feeling this isn't possible with the current API, but I have to ask. Is it possible to query a particular QObject's signal or slot name (from the metaObject) and retrieve all the QObjects and their slot or signals names that are connected to it?

I'm doing this because, in effect, I have a large number of layouts that contain an identical arrangement of widgets, for each layout there an object and each of the layout's widgets control the various properties of it. I want to keep one layout, and connect it's widgets' signal/slots to all the other objects in the same pattern, but in order to do this I need to 'record' all the signal-slot data.

Is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅淡淡 2024-12-03 10:44:35

Qt 中有一个有趣的文件 - %Qtdir%/src/corelib/kernel/qobject_p.h,它包含 Qt 内部使用的类 QObjectPrivate
使用
static QObjectPrivate *get(QObject *o) 函数来获取小部件的 QObjectPrivate 成员,并尝试调用其有趣的成员,例如
QObjectList receiveList(const char *signal) const;QObjectList senderList() const;。文件完全没有记录,但它似乎包含您所需要的内容......

There is an interesting file in Qt - %Qtdir%/src/corelib/kernel/qobject_p.h, it contains class QObjectPrivate, used by Qt internally.
Use
static QObjectPrivate *get(QObject *o) function to get QObjectPrivate member for your widgets, and try to call its interesting members like
QObjectList receiverList(const char *signal) const; or QObjectList senderList() const;. File is totally undocumented, but it seems to contain exactly what you need...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文