Pyside连接错误:RuntimeError:无法连接信号clicked()

2024-04-19 00:25:34 发布

您现在位置:Python中文网/ 问答频道 /正文

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()信号连接到slot,slot是一个函数set(),但它不能运行。在

^{pr2}$

Tags: fromimportselfformappinitdefsys
2条回答

您不需要将信号连接到您的set()-函数,而是连接到它的返回值。您只需删除括号,它就可以工作了:

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

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

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

def set(self, index):

    self.stackedWidget.setCurrentIndex(index)

相关问题 更多 >