[PyKDE] Problem (re)connecting QWizard buttons

Phil Thompson phil at riverbankcomputing.co.uk
Sat Jun 25 12:37:32 BST 2005


On Friday 24 June 2005 11:16 am, Ulrich Berning wrote:
> Look at the following code:
>
> (Yes, I know that reimplementing accept() is the better way)
>
> ---8<---------------------->8---
> import sys
> from qt import *
>
> class MyWizard(QWizard):
>      def __init__(self,parent=None,name="",modal=False,fl=0):
>          QWizard.__init__(self,parent,name,modal,fl)
>
>          # Disconnect the default slot
>          self.disconnect(self.finishButton(),
>                          SIGNAL('clicked()'),
>                          self, SLOT('accept()'))
>
>          # With the lastest sip/PyQt snapshots,
>          # this additional reference is necessary
>          # *before* we connect to our own slot
>          # ---
>          # With sip-4.2.1/PyQt-3.14.1, this
>          # additional reference wasn't necessaray.
>          # Is this a bug or an intentional change?
>          self.fb = self.finishButton()
>
>          # Connect to our own slot
>          self.connect(self.finishButton(),
>                       SIGNAL('clicked()'),
>                       self.myFinishSlot)
>
>      def myFinishSlot(self):
>          print "myFinishSlot()"
>          self.accept()
>
> if __name__ == "__main__":
>      a = QApplication(sys.argv)
>      QObject.connect(a, SIGNAL("lastWindowClosed()"),
>                      a, SLOT("quit()"))
>      w = MyWizard()
>      w.show()
>      a.exec_loop()
> ---8<---------------------->8---
>
> With the latest sip/PyQt snapshots, I have to store an additional
> reference to the finishButton instance before I connect the signal to my
> own slot, otherwise the slot gets never called.
>
> With sip-4.2.1/PyQt-3.14.1 this additional reference wasn't necessary.
>
> Is this a bug or an intentional change? I haven't found anything
> specific in the ChangeLogs.

It's a side-effect of the new support for the cyclic garbage collector. For 
connections to Python callables a proxy QObject is created. This was being 
destroyed when the signal emitter was garbage collected.

I've changed it so that the proxy is only destroyed if the signal emitter is 
owned by Python.

Thanks,
Phil




More information about the PyQt mailing list