[PyQt] event() gets called but C++ object already deleted

Wilbert Berendsen wbsoft at xs4all.nl
Wed May 25 08:37:44 BST 2011


Hi,

I have a PyQt4 subclass of a QToolButton that implements event() (to show 
custom tooltips as they need to appear):

    def event(self, ev):
        if ev.type() == QEvent.ToolTip:
            # handle it.....
            return True
        return super(Button, self).event(ev)

The problem is that on Windows, while the application is closing itself, 
event() gets called (with a QActionEvent) while the super() call results in a 
RuntimeError: underlying C/C++ object has been deleted.

Changing the super() line into 'return QToolButton.event(self, ev)' does not 
help.

Is it a correct workaround to simply wrap the return super... line in a 
try/except clause? Or is there a better way to prevent this?

Can I prevent that event() is called while the c++ object is not living 
anyway?

with best regards,
Wilbert Berendsen

-- 
http://www.wilbertberendsen.nl/
"You must be the change you wish to see in the world."
        -- Mahatma Gandhi


More information about the PyQt mailing list