pyside连接错误“RuntimeError:连接信号无法点击()”

时间:2012-12-15 18:19:06

标签: python pyside qt-designer

from PySide.QtCore import *
from PySide.QtGui import *

import sys
import stackwid

class Dialog(QDialog,stackwid.Ui_Dialog):

    def __init__(self,parent = None):
        super(Dialog,self).__init__(parent)
        self.setupUi(self)


        self.camButton.clicked.connect(self.set())


    def set(self):

        self.stackedWidget.setCurrentIndex(1)


app = QApplication(sys.argv)
form = Dialog()
form.show()
app.exec_()

我想将camButton(PushButton)发出的clicked()信号连接到一个函数set()的插槽。这只是不运行。

RuntimeError: Failed to connect signal clicked()

2 个答案:

答案 0 :(得分:10)

您不会将信号连接到set() - 函数,而是连接到它的返回值。你只需要删除括号,然后它应该工作:

self.camButton.clicked.connect(self.set)

答案 1 :(得分:4)

将额外的参数传递给插槽,这可能会对你有所帮助,祝你好运!

self.camButton.clicked.connect(lambda: self.set(index))

def set(self, index):

    self.stackedWidget.setCurrentIndex(index)