给定pyqtBoundSignal如何确定插槽? [英] Given a pyqtBoundSignal how to determine the slot?

查看:411
本文介绍了给定pyqtBoundSignal如何确定插槽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出信号后,如何确定特定信号所连接的插槽?

Given the signal, how can I determine the slot that a particular signal is connected to?

我熟悉如何连接信号和插槽,这更多是出于调试目的。

I am familiar with how to connect signal and slots, this is more for debugging purposes.

我是使用pyqt5,python 2.7

I am using pyqt5, python 2.7

推荐答案

没有 the插槽,因为一个信号可以连接到多个插槽,或多个其他信号,或同一信号/插槽多次。但是无论如何,没有内置的API可以列出所有当前连接。

There is no such thing as "the" slot, because a signal can be connected to multiple slots, or multiple other signals, or the same signal/slot multiple times. But in any case, there is no built-in API that can list all the current connections.

您可以获得当前连接的 count 信号的连接,例如:

You can get a count of the current connections for a signal, like this:

    count = button.receivers(button.clicked)

还有 connectNotify disconnectNotify -但这不会使您走得更远,因为重新实现这些方法只会告诉您该对象连接或断开的信号。

There is also connectNotify and disconnectNotify - but that doesn't get you much further, because reimplementing those methods will only tell you which signals were connected or disconnected for the object.

QtTest 模块具有 QSignalSpy (仅在PyQt5中可用),它可以记录给定信号的所有发射。但是,再次,这只会给您发送的参数,而不是参数发送到的位置。

The QtTest module has QSignalSpy (only available in PyQt5), which can record all the emissions of a given signal. But, again, that will only give you the arguments that were sent, rather than where they were sent to.

我想Qt不提供API的原因

I suppose the reason why Qt doesn't provide an API for this is that the list of connected items is potentially very volatile.

PS:

我忘了提 dumpObjectInfo ,它显然可以满足您的要求,但是只能与Qt的调试版本一起使用-对于发布版本,它什么也不做。

I forgot to mention dumpObjectInfo, which apparently does what you're asking for, but will only work with a debug build of Qt - for release builds, it does nothing.

这篇关于给定pyqtBoundSignal如何确定插槽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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