Given a pyqtBoundSignal how to determine the slot?(给定一个 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.
您可以获得一个信号的当前连接的计数,如下所示:
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 如何确定插槽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:给定一个 pyqtBoundSignal 如何确定插槽?
基础教程推荐
- 筛选NumPy数组 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01