PyQt4 signals and slots

后端 未结 7 1842
执笔经年
执笔经年 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:17

    As noted by gruszczy you have to use the same QtCore.SIGNAL('xxx') to connect signal and to emit it. Also I think you should use Qt types in the arguments list of signal function. E.g.:

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

    And then emit with:

    self.emit(QtCore.SIGNAL("aa(QString&)"), "jacek")
    

    Sometimes it makes sense to define signal only once as global variable and use it elsewhere:

    MYSIGNAL = QtCore.SIGNAL("aa(QString&)")
    ...
    QtCore.QObject.connect(self.loginDialog, MYSIGNAL, self.login)
    ...
    self.emit(MYSIGNAL, "jacek")
    

提交回复
热议问题