PyQt4 signals and slots

后端 未结 7 1843
执笔经年
执笔经年 2021-01-31 06:40

I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:

self.loginDialog = LoginDialog();
         


        
7条回答
  •  一向
    一向 (楼主)
    2021-01-31 07:07

    I checked your code and it looks like the problem is in the way how you're connecting your signal

    1. you emit the signal in Ui_Dialog class

      self.emit(QtCore.SIGNAL("aa()"))

    2. you connect to the signal in Ui_MainWindow's setupUi method by calling

      QtCore.QObject.connect(self.loginDialog.ui, QtCore.SIGNAL("aa()"), self.login)

    notice first parameter is changed to self.loginDialog.ui; your original connect call was using self.loginDialog which is of the LoginDialog type, whereas signal is emitted by the Ui_Dialog class which is ui property of the LoginDialog. After this change login method of the Ui_MainWindow got called

    hope this helps, regards

提交回复
热议问题