如何确定谁发出了信号? [英] How to determine who emitted the signal?

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

问题描述

我在 PyQt 上开发了一个应用程序,我喜欢信号槽模型,但是有什么方法可以确定信号的发射器?我希望有一种方法,因为它可以让我们编写更通用的代码,而无需为每个相似的信号定义大量槽.

I develop an application on PyQt, I like the signal-slot model, but is there any way to determine the emitter of signal? I hope that there is a way, because it will let to write more generic code without defining lots of slots for each similar signal.

推荐答案

我觉得我开题太早了,因为我自己在google上找到了答案.当插槽被发射器激活时,发射器的指针被存储,可以通过

I think that I opened a question too early, because I found an answer on google by myself. When slot is activated by emitter, the pointer of emitter stored, and can be retrieved by

QObject::sender()

因此可以通过以下方式在 PyQt 中访问:

and as a result can be accessed in PyQt by:

@QtCore.pyqtSlot()
def someSlot(self):
    self.sender()

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

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