【发布时间】:2012-01-09 21:58:10
【问题描述】:
我正在阅读“使用 Python 和 Qt 进行快速 GUI 编程”一书,但在信号/插槽项目上遇到了问题。我已经下载了作者的代码以与我自己的代码进行比较,它们看起来都一样,但是,当我从派生的旋转框类发出信号时,python 就会崩溃。这是我拥有的全部代码:
import sys
from PySide.QtCore import *
from PySide.QtGui import *
class ZeroSpinBox(QSpinBox):
zeros = 0
def __init__(self, parent=None):
super(ZeroSpinBox, self).__init__(parent)
self.connect(self, SIGNAL("valueChanged(int)"), self.checkzero)
def checkzero(self):
if self.value() == 0:
self.zeros += 1
self.emit(SIGNAL("atzero"), self.zeros)
class Form(QDialog):
def __init__(self, parent= None):
super(Form, self).__init__(parent)
dial = QDial()
dial.setNotchesVisible(True)
spinbox = ZeroSpinBox()
spinbox.setRange(0,200)
dial.setRange(0,200)
layout = QHBoxLayout()
layout.addWidget(dial)
layout.addWidget(spinbox)
self.setLayout(layout)
self.connect(dial, SIGNAL("valueChanged(int)"), spinbox, SLOT("setValue(int)"))
self.connect(spinbox, SIGNAL("valueChanged(int)"), dial, SLOT("setValue(int)"))
self.connect(spinbox, SIGNAL("atzero"), self.announce)
self.setWindowTitle("Signals and Slots Part 2")
def announce(self, zeros):
print "ZeroSpinBox has been at zero %d times" % zeros
if __name__ == "__main__":
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
我的问题发生在 spinbox 降为零时,checkzero(self) 方法(ZeroSpinBox 类的)被调用,self.zeros += 1 行正常,然后在发射行窗口报告 Python。 exe崩溃了。我得到的错误是“python.exe 已停止工作”,控制台报告“进程已完成,退出代码 -1073741819”
知道为什么会这样吗?这是 Python 2.7.2 和 PyQT4 w/PySide。
【问题讨论】:
-
尝试了另一个执行发射的程序,同样的事情......
标签: python signals-slots pyside