擅长:python、mysql、java
<p>您发布的示例代码至少有三处错误:</p>
<ol>
<li><p>您试图传递可调用对象的<em>返回值</em>,而不是可调用对象本身。所以去掉最后一个参数中的括号:</p>
<pre><code>QtCore.QObject.connect(self.ui.comboBox,
QtCore.SIGNAL("currentIndexChanged()"),
self.comboBoxIndexChanged)
</code></pre></li>
<li><p>您试图在定义可调用项之前引用它。这可能是由于缩进错误造成的,因此受影响的部分应该如下所示:</p>
<pre><code>class ConverterDialog(QtGui.QDialog):
def __init__(self, parent = None):
...
QtCore.QObject.connect(self.ui.comboBox,
QtCore.SIGNAL("currentIndexChanged()"),
self.comboBoxIndexChanged)
def comboBoxIndexChanged(self):
return 1
</code></pre></li>
<li><p>您使用的是丑陋且容易出错的<a href="http://pyqt.sourceforge.net/Docs/PyQt4/old_style_signals_slots.html" rel="nofollow">old-style signal and slot syntax</a>,而您可以使用优雅的python<a href="http://pyqt.sourceforge.net/Docs/PyQt4/new_style_signals_slots.html" rel="nofollow">new-style syntax</a>。请帮你自己一个忙,把你所有的信号连接都写成这样:</p>
<pre><code>self.ui.comboBox.currentIndexChanged.connect(self.comboBoxIndexChanged)
</code></pre></li>
</ol>