[PyQt] Bug in QTableView.setModel()

Aaron Digulla digulla at hepe.com
Tue Jan 8 16:36:05 GMT 2008

Quoting Aaron Digulla <digulla at hepe.com>:

> Another wa would be to save all objects which pass through SIP in map
> (QObject -> Python wrapper), connect to the destroyed(QObject) signal
> and check the state when it is emitted. Does SIP notice when the python
> wrapper is destroyed? If not, it's probably possible to patch the GC
> code of Python to call an additional routine for the wrapper objects.

I whipped together a quick example of what I have in mind:

import traceback
from PyQt4.QtCore import SIGNAL, QObject

guards = {}

class Ouch(QObject):
     def __init__(self):
         self.st = traceback.format_stack()

     def punch(self):
         print 'Guarded object was destroyed'
         print self.st[-3]

def guard(o):
     g = Ouch()
     assert g.connect(o, SIGNAL('destroyed()'), g.punch)
     guards[g] = None
     return o

o = guard(QObject())
del o

That prints:

Guarded object was destroyed
   File "t.py", line 31, in <module>
     o = guard(QObject())

Probably not the whole nine yards but maybe two, or so...


Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."

More information about the PyQt mailing list