PySide가 주장하는 바는 Signals can be defined using the QtCore.Signal() class. Python types and C types can be passed as parameters to it. If you need to overload it just pass the types as tuples or lists
입니다. PySide Doc Signals and Slots in PySide에서 한 번에 여러 신호를 생성하는 방법을 보여주었습니다. 그 라인은 다음과 같습니다PySide 신호가 Python 클래스를 오버로드 할 수 없습니다.
# create two new signals on the fly: one will handle
# int type, the other will handle strings
speak = QtCore.Signal((int,), (str,))
내가 지금까지 조금 가서 (학습 목적)이 같은 것을 만들어 :
speak = QtCore.Signal((int,), (str,), (tuple,), (list,), (A,), (B,), (Exception,), (unicode,), (float,))
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>
Obersevation : tuple
, list
, Exception
내 사용자 정의 A
및 B
있어 동일한 신호를 . 터플과리스트는 약간 일반적이고 PySide에서 물건을 오버로드하는 데 사용된다는 것을 알고 있습니다. 그러나 왜 내 A
과 B
도 같은 신호를 얻습니까? 파이썬에서 int
, float
및 str
과 같은 진짜 원시 형식이 새 신호를 얻는 것처럼 보입니다.
누구나이 이상한 행동을 설명 할 수 있습니까?
미리 감사드립니다. 내가 진짜 PySide 프로젝트에서 문제가 발생하는 경우
[업데이트]
나는 탐사 이상했다. 나는이에 실제 버전을 단순화 :
#!/usr/bin/env python
import sys
from PySide import QtCore
class A(object):
def __init__(self, msg):
self.msg = msg
class B(object):
def __init__(self, msg):
self.msg = msg
@QtCore.Slot(A)
def sayA(a):
print 'From sayA:', a.msg
@QtCore.Slot(B)
def sayB(b):
print 'From sayB:', b.msg
class Communicate(QtCore.QObject):
speak = QtCore.Signal((A,), (B,))
someone = Communicate()
someone.speak[A].connect(sayA)
someone.speak[B].connect(sayB)
someone.speak[A].emit(A('A is good'))
someone.speak[B].emit(B('B is bad'))
그것은 인쇄됩니다
From sayA: A is good
From sayB: A is good
From sayA: B is bad
From sayB: B is bad
나는
A is good
만 사야에서 인쇄 할 것으로 예상.
유효한 설명. 그래서 PySide는 파이썬 객체를 받아들이지 만 그것들을 구별하지는 않습니다. 고마워요! – foresightyj