PyQt4 signals and slots

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

    What @bialix suggested should have worked, but try an alternative way of connecting:

    class Foo(QtCore.QObject):
        mysignal = QtCore.pyqtSignal(str, name='mysignal')
    
        def connect_to_signal(self):
            # you can use this syntax instead of the 'old' one
            self.mysignal.connect(self.myslot)
    
            # but this will also work
            self.connect(self, QtCore.SIGNAL('mysignal(QString)'), self.myslot) 
    
            self.mysignal.emit("hello")
    
        def myslot(self, param):
            print "received %s" % param
    

    For a more detailed explanation of how signals/slots work in PyQt I'd suggest going through it's documentation, specifically this section.

提交回复
热议问题