[PyKDE] Now tackle dtor strangeness

Hans-Peter Jansen hpj at urpla.net
Sun Jan 26 00:08:01 GMT 2003


On Saturday 25 January 2003 17:02, Phil Thompson wrote:
>
> Thanks for putting the effort into this - it was very helpful. The bug is
> that qspinbox.sip should say...
>
> bool eventFilter(QObject *,QEvent *);
>
> ...instead of...
>
> void eventFilter(QObject *,QEvent *);
>
> It will be fixed in tonight's snapshot.

Thanks. Well done. I feel better now. But please have another look into 
these two:

> > > qApp.quit(). Phil, it appears, that the QSpinBox base class disappears
> > > while subclassed SpinBox event() handler is active. This doesn't look
> > > right to me.
> >
> > While making both versions functional identical, I've rewritten the event
> > decoder qEvent(), but couldn't believe my eyes: during qApp.quit() the
> > value of the global defined qEventDict{} in the .py script is replaced
> > with a None value somewhere under the covers! Please remove the
> >
> > Something is definitely going wrong here.
>
> I think this is just Python and Qt racing each other to tidy up. As the
> behaviour of either isn't formally documented I think it's more a feature
> rather than a bug.

Well, I cannot see the feature aspect here. OTOH, this obfuscates the code, 
and it defies the principle of least surprise.

I digged into this a bit further and found a way to get around these problems
somehow:

1) The qEventDict does survive, if it is declared inside the qEvent function.

2) just keep a reference of QSpinBox, and call it, instead of the baseclass:

class SpinBox(QSpinBox):
    def __init__(self, minValue, maxValue, step = 1, parent = None, name = None):
        self.lastval = None
        QSpinBox.__init__(self, minValue, maxValue, step, parent, name)
        self.QSpinBox = QSpinBox

    def event(self, e):
        t = e.type()
        print "SpinBox event:", qEvent(t)
        return self.QSpinBox.event(self, e)

Funny side note: it was enough to fix one of both sub classes this way to 
prevent attribute errors here. This is pretty undeterministic, and that's 
exactly the reason, why I don't like this behaviour...

Phil, one would expect, that as long as a class exists, its baseclass should 
exist, either. The same goes for globals in module scope.

Note, that this happens, before dtor of QApplication aka PyQtDisownTopLevelWidgets(),
and even siplib:finalise() is called:

closeEvent
exec_loop: 0
PushButton event: WindowDeactivate
SpinBox event: WindowDeactivate
PushButton event: FocusOut
PushButton focusOutEvent
PushButton event: Hide
SpinBox event: Hide
PyQtDisownTopLevelWidgets
PyQtDisownTopLevelWidgets
finalise begin
finalise done

Is it possible to keep a reference on these internally and throw them away in
finalise()? For reference, current sbtest.py attached.

> Phil

Pete
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sbtest.py
Type: text/x-python
Size: 6172 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20030126/ddc7ef70/sbtest.py


More information about the PyQt mailing list