[PyKDE] ref counting

Stefan Seefeld seefeld at sympatico.ca
Sat Feb 14 04:51:01 GMT 2004


hi there,

I'm experimenting with pyqt and I'm running in
some strange behavior.
The examples3/canvas/canvas.py demo contains
the following lines:

     def newView(self):
         self.m=Main(self.canvas,None,"new windiw",Qt.WDestructiveClose)
         qApp.setMainWidget(self.m)
         self.m.show()
         qApp.setMainWidget(None)

What I'm wondering about is the reason for the 'Main' instance to
be stored in an attribute. In fact, if I replace 'self.m' by 'm'
the applet doesn't work any more, i.e. as soon as I create the
second view the first will be destructed. What's the reason for
this ? It appears the ref count for the view drops to zero so
it gets destroyed...
But in the above, it would seem the second call to 'newView' would
free the first view, and thus destroy it, too. That, however, is
not the case.

The reason I'm asking is because I'm using a modified version
of the canvas.py demo, where this behavior is even more disturbing,
i.e. I don't get more than one view at any given time.

Any help would be highly appreciated !

Stefan




More information about the PyQt mailing list