On Thursday 01 May 2008, Giovanni Bajo wrote:
> On Wed, 2008-04-30 at 22:18 +0200, Aaron Digulla wrote:
> > Phil Thompson schrieb:
> > >> - For everything derived from QObject, connect to the dispose signal.
> > >> At this time, save a stack trace and a pointer to the Python handle
> > >> associated with the QObject
> > >> - When the signal is emitted, make sure that the usage count of the
> > >> corresponding Python object is 0, too. If it isn't, print the saved
> > >> stack trace and a new one saying that the usage count between Python
> > >> and C++ is out of sync.
> > >>
> > >> For the installation, the debug versions of the libraries should go
> > >> into special directories so I can put them in the PATH (Windows) or
> > >> the LD_LIBRARY_PATH (Linux) to select them when my code behaves odd.
> > >
> > > I'm not sure what that gives you. I would imagine that a QObject
> > > disappearing while there is still a Python wrapper for it is quite
> > > common and legitimate. For example, if you keep a reference to a child
> > > object and the parent gets destroyed. The problem is only when you try
> > > and use that reference - but if you do then you will get an exception
> > > anyway.
> >
> > I get a core dump and on Windows, I get nothing. Even if I could get a
> > core file, it wouldn't tell me where the object was created.
> >
> > So maybe the trick would be to declare the Python object as "invalid" as
> > soon as the dispose signal was received. After that, any call to any
> > method should raise an exception.
>
> This is exactly what PyQt (or rather SIP) does, for every Python wrapper
> of a PyQt object. Whenever the QObject dies, the Python object is
> flagged as invalid, and any usage of it results in a RuntimeError;
> moreover, you can check for this invalid condition through
> sip.isdeleted().
>
> Thus, I'm not sure what you are speaking of.

I nearly gave the same reply, but realised I was wrong. The above is true only 
for QObjects created from Python because the death of the QObject is detected 
by the virtual dtor not by the destroyed() signal.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to