Qt 从小部件获取信号槽连接信息
我感觉当前的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 classQObjectPrivate
, 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 likeQObjectList receiverList(const char *signal) const;
orQObjectList senderList() const;
. File is totally undocumented, but it seems to contain exactly what you need...