我正在尝试运行以下 PySide Qt Python 示例(代码位于此问题的底部):
https://github.com/Deusdies/pythonbo/blob/master/06-sixthTutorial-moresignals.py
我收到一条错误消息:
断言:文件 /tmp/pyside-gUBW/pyside-qt4.8+1.1.2/libpyside/signalmanager.cpp 中的“pyMethod”,第 444 行
知道为什么会发生这种情况,我正在使用 Mac OS X 10.8.3 完全按原样运行代码。我通过 HomeBrew 安装了 Python 2.7.4 以及 qt 和 pyside。
任何帮助,将不胜感激!
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 not self.value():
self.zeros += 1
self.nulls = 5
self.emit(SIGNAL("atZero"), self.zeros, self.nulls)
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
dial = QDial()
dial.setNotchesVisible(True)
zeroSpinBox = ZeroSpinBox()
layout = QHBoxLayout()
layout.addWidget(dial)
layout.addWidget(zeroSpinBox)
self.setLayout(layout)
self.connect(dial, SIGNAL("valueChanged(int)"), zeroSpinBox.setValue)
self.connect(zeroSpinBox, SIGNAL("valueChanged(int)"), dial.setValue)
self.connect(zeroSpinBox, SIGNAL("atZero"), self.announce)
self.setWindowTitle("Signals and Slots")
def announce(self, zeros, nulls):
print "Announcing!!!"
app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
信号管理器.cpp
我设法在网上找到了一个包含有问题的 signalmanager.cpp 源文件的存储库:
https://github.com/jasonmccampbell/PySide/blob/master/libpyside/signalmanager.cpp#L444
这是第 444 行的摘录:
int SignalManager::callPythonMetaMethod(const QMetaMethod& method, void** args, PyObject* pyMethod, bool isShortCuit)
{
Q_ASSERT(pyMethod); // This is the line causing the exception?
Shiboken::GilState gil;
PyObject* pyArguments = 0;