PySide信号不能重载Python类

PySide信号不能重载Python类,python,qt,signals,pyside,slot,Python,Qt,Signals,Pyside,Slot,PySide声称可以使用QtCore.Signal()类定义信号。Python类型和C类型可以作为参数传递给它。如果需要重载,只需将类型作为元组或列表传递即可。从PySide文档中,他们展示了一种同时创建多个信号的方法。这条线是: # create two new signals on the fly: one will handle # int type, the other will handle strings speak = QtCore.Signal((int,), (str,))

PySide声称可以使用QtCore.Signal()类定义
信号。Python类型和C类型可以作为参数传递给它。如果需要重载,只需将类型作为元组或列表传递即可
。从PySide文档中,他们展示了一种同时创建多个信号的方法。这条线是:

# create two new signals on the fly: one will handle
# int type, the other will handle strings
speak = QtCore.Signal((int,), (str,))
我走得有点远,创建了这样的东西(出于学习目的):

A
B
是我创建的两个不同的虚拟新样式类。然后我调查了通过打印出的信号实际产生了多少信号:

print someone.speak
print someone.speak[int]
print someone.speak[str]
print someone.speak[tuple]
print someone.speak[list]
print someone.speak[A]
print someone.speak[B]
print someone.speak[Exception]
print someone.speak[unicode]
print someone.speak[float]
我得到了这些:

<PySide.QtCore.SignalInstance object at 0x02179BA0>
<PySide.QtCore.SignalInstance object at 0x02179BA0>
<PySide.QtCore.SignalInstance object at 0x02179BB0>
<PySide.QtCore.SignalInstance object at 0x02179BC0>
<PySide.QtCore.SignalInstance object at 0x02179BC0>
<PySide.QtCore.SignalInstance object at 0x02179BC0>
<PySide.QtCore.SignalInstance object at 0x02179BC0>
<PySide.QtCore.SignalInstance object at 0x02179BC0>
<PySide.QtCore.SignalInstance object at 0x02179BB0>
<PySide.QtCore.SignalInstance object at 0x02179C00>
它将打印出:

From sayA: A is good
From sayB: A is good
From sayA: B is bad
From sayB: B is bad
我希望仅从sayA打印
A是好的

查看与您的问题相关的问题:

是可以使用python对象定义信号,您可以使用:

信号\节点\所选=QtCore.signal(对象)

我假设传递任何自定义Python类都被视为传递
object
。无法让信号区分它们。

请查看与您的问题相关的问题:

是可以使用python对象定义信号,您可以使用:

信号\节点\所选=QtCore.signal(对象)


我假设传递任何自定义Python类都被视为传递
object
。没有办法让信号区分它们。

感谢您的研究!我也有同样的问题,通过链接信号和使用替代名称来携带不同的数据来解决:

class King(QtGui.QWidget):
    summon = QtCore.Signal(str)
    summon_knights = QtCore.Signal(object)

    def __init__(self, parent=None):
        super(King, self).__init__(parent=parent)

        summon.connect(lambda x: self.summon_knights.emit(self.get_available_knights()))

    def get_available_knights(self):
        return ["Lancelot", "Galahad"]
lambda是为了处理或忽略召唤信号携带的str

这是我不太优雅的抓挠工作,目的是向自己证明它的行为并不是我想要的。休眠是为了迫使结果按时间顺序排列,因为异步信号/插槽行为会导致结果变得非常混乱(这有利于提高速度,但很难解释)

以下是输出:

Telling analyst to start
Analyst working!
Analyst done!
Results type (expecting OrderedDict): <class 'collections.OrderedDict'>
Sum of Results: 150.0
Not all tasks completed yet
Report type (expecting list): <class 'collections.OrderedDict'>
*** WRONG TYPE! LIST slot got the DICT!
Results type (expecting OrderedDict): <type 'list'>
*** WRONG TYPE! DICT slot got the LIST!
Report type (expecting list): <type 'list'>
Report of original result: 
Analysis Report
 a: 100.0
 b: 50.0
All tasks completed
具有以下输出:

Telling analyst to start
Analyst working!
Analyst done!
Results type (expecting OrderedDict): <class 'collections.OrderedDict'>
Sum of Results: 150.0
Not all tasks completed yet
Report type (expecting list): <type 'list'>
Report of original result: 
Analysis Report
 a: 100.0
 b: 50.0
All tasks completed
告诉分析员开始
分析师在工作!
完成了!
结果类型(预期订单数据):
结果总和:150.0
尚未完成所有任务
报告类型(应为列表):
原始结果报告:
分析报告
a:100.0
b:50.0
所有任务都已完成

感谢您的研究!我也有同样的问题,通过链接信号和使用替代名称来携带不同的数据来解决:

class King(QtGui.QWidget):
    summon = QtCore.Signal(str)
    summon_knights = QtCore.Signal(object)

    def __init__(self, parent=None):
        super(King, self).__init__(parent=parent)

        summon.connect(lambda x: self.summon_knights.emit(self.get_available_knights()))

    def get_available_knights(self):
        return ["Lancelot", "Galahad"]
lambda是为了处理或忽略召唤信号携带的str

这是我不太优雅的抓挠工作,目的是向自己证明它的行为并不是我想要的。休眠是为了迫使结果按时间顺序排列,因为异步信号/插槽行为会导致结果变得非常混乱(这有利于提高速度,但很难解释)

以下是输出:

Telling analyst to start
Analyst working!
Analyst done!
Results type (expecting OrderedDict): <class 'collections.OrderedDict'>
Sum of Results: 150.0
Not all tasks completed yet
Report type (expecting list): <class 'collections.OrderedDict'>
*** WRONG TYPE! LIST slot got the DICT!
Results type (expecting OrderedDict): <type 'list'>
*** WRONG TYPE! DICT slot got the LIST!
Report type (expecting list): <type 'list'>
Report of original result: 
Analysis Report
 a: 100.0
 b: 50.0
All tasks completed
具有以下输出:

Telling analyst to start
Analyst working!
Analyst done!
Results type (expecting OrderedDict): <class 'collections.OrderedDict'>
Sum of Results: 150.0
Not all tasks completed yet
Report type (expecting list): <type 'list'>
Report of original result: 
Analysis Report
 a: 100.0
 b: 50.0
All tasks completed
告诉分析员开始
分析师在工作!
完成了!
结果类型(预期订单数据):
结果总和:150.0
尚未完成所有任务
报告类型(应为列表):
原始结果报告:
分析报告
a:100.0
b:50.0
所有任务都已完成

这似乎是一个有效的解释。因此PySide接受Python对象,但不区分它们。谢谢!这似乎是一个合理的解释。因此PySide接受Python对象,但不区分它们。谢谢!
Telling analyst to start
Analyst working!
Analyst done!
Results type (expecting OrderedDict): <class 'collections.OrderedDict'>
Sum of Results: 150.0
Not all tasks completed yet
Report type (expecting list): <type 'list'>
Report of original result: 
Analysis Report
 a: 100.0
 b: 50.0
All tasks completed