Python 当信号找不到其插槽时
单击按钮会导致进程崩溃。有什么不对劲吗Python 当信号找不到其插槽时,python,qt,pyqt,signals,pyside,Python,Qt,Pyqt,Signals,Pyside,单击按钮会导致进程崩溃。有什么不对劲吗 from PySide import QtCore, QtGui class button(QtGui.QPushButton): def __init__(self, parent=None): super(button, self).__init__(parent) self.clicked.connect(self.click) self.show() def click(self
from PySide import QtCore, QtGui
class button(QtGui.QPushButton):
def __init__(self, parent=None):
super(button, self).__init__(parent)
self.clicked.connect(self.click)
self.show()
def click(self):
self.emit(QtCore.SIGNAL('customSignal'), 'String Argument')
btn = button()
class label(QtGui.QLabel):
def __init__(self, parent=None):
super(label, self).__init__(parent)
self.connect(btn, QtCore.SIGNAL('customSignal'), self.Function)
self.show()
@QtCore.Slot(str)
def Function(self, arg=None):
print 'Function arg: %r'%arg
lbl = label()
不需要
@QtCore.Slot
装饰器:
from PyQt4 import QtCore, QtGui
import sys
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
class button(QtGui.QPushButton):
def __init__(self, parent=None):
super(button, self).__init__(parent)
self.clicked.connect(self.click)
self.show()
def click(self):
self.emit(QtCore.SIGNAL('customSignal'), 'String Argument')
btn = button()
class label(QtGui.QLabel):
def __init__(self, parent=None):
super(label, self).__init__(parent)
self.connect(btn, QtCore.SIGNAL('customSignal'), self.method)
self.show()
def method(self, arg=None):
print 'method arg: %r'%arg
lbl = label()
sys.exit(app.exec_())
==================
from PySide import QtCore, QtGui
def function(arg=None):
print 'function arg: %r'%arg
class button(QtGui.QPushButton):
def __init__(self, parent=None):
super(button, self).__init__(parent)
self.clicked.connect(self.click)
self.show()
def click(self):
self.emit(QtCore.SIGNAL('customSignal'), 'String Argument')
btn = button()
class label(QtGui.QLabel):
def __init__(self, parent=None):
super(label, self).__init__(parent)
self.connect(btn, QtCore.SIGNAL('customSignal'), function)
self.show()
lbl = label()
====
不需要
@QtCore.Slot
装饰器:
from PyQt4 import QtCore, QtGui
import sys
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
class button(QtGui.QPushButton):
def __init__(self, parent=None):
super(button, self).__init__(parent)
self.clicked.connect(self.click)
self.show()
def click(self):
self.emit(QtCore.SIGNAL('customSignal'), 'String Argument')
btn = button()
class label(QtGui.QLabel):
def __init__(self, parent=None):
super(label, self).__init__(parent)
self.connect(btn, QtCore.SIGNAL('customSignal'), self.method)
self.show()
def method(self, arg=None):
print 'method arg: %r'%arg
lbl = label()
sys.exit(app.exec_())
==================
from PySide import QtCore, QtGui
def function(arg=None):
print 'function arg: %r'%arg
class button(QtGui.QPushButton):
def __init__(self, parent=None):
super(button, self).__init__(parent)
self.clicked.connect(self.click)
self.show()
def click(self):
self.emit(QtCore.SIGNAL('customSignal'), 'String Argument')
btn = button()
class label(QtGui.QLabel):
def __init__(self, parent=None):
super(label, self).__init__(parent)
self.connect(btn, QtCore.SIGNAL('customSignal'), function)
self.show()
lbl = label()
====