[PyKDE] Quitting invokes crash handler

Gordon Tyler gordon at doxxx.net
Fri Aug 30 22:12:00 BST 2002


Jim Bublitz wrote:
> On 30-Aug-02 Gordon Tyler wrote:
>>Jim Bublitz wrote:
>>>On 29-Aug-02 Gordon Tyler wrote:
>>>>Frederick Polgardy Jr wrote:
>>>>>  a.connect(a, SIGNAL("lastWindowClosed()"), w.fileQuit)
>>>>
>>>>I would write the above line like this (wordwrapped for
>>>>reading):
>>>
>>>>    a.connect(a, SIGNAL("lastWindowClosed()"),
>>>>        KApplication.kApplication(), SLOT("quit()"))
>>>
>>>The original line is both correct and different in function from
>>>your suggested rewrite. 'w.fileQuit' might actually do something
>>>useful (like save files, cleanup, etc) in a real program.
>>
>>But wouldn't that connection be referring to a slot on an
>>instance that no longer exists? w is the only window, when it
>>is closed, the lastWindowClosed signal is fired, but the
>>instance that it connects to is gone. Or am I misunderstanding
>>the lifecycle of the w instance?
> 
> I see your point and don't actually know the answer - that's
> another reason I'd opt for the 'queryClose' and 'queryExit'
> functions that are part of the KMainWindow class.

I agree. Those are more suitable for doing per-window cleanup or close 
verification. A fileClose slot that is normally connected to a menu item 
shouldn't do anything more than invoke self.close() because anything 
else that it does will not be executed if the user closes the window 
using the titlebar X button or if the system is shutting the app down 
because the user is logging out.

The way I see it, KApplication::lastWindowClosed is a way of stopping 
the application event loop when the last window is closed. If necessary, 
a subclass of KApplication should be created with a custom slot like 
"shutdownApplication()" to which lastWindowClosed is connected that does 
global _application_ shutdown stuff and calls KApplication::quit().

> I have seen the idiom above used in a number of places and it
> generally seems to work (it works when PyKDE is fixed by adding the
> KApplication dtor referenced in another post). It depends a lot on
> what 'lastWindowClosed' actually means (I haven't looked) and also
> on whether 'w' being closed (or removed from the app's widget
> list) == 'w' being destroyed - the two aren't necessarily the same. 
> For example, 'dialog closed' != 'dialog destroyed'.

Which is why I think it's a bad idiom, and a bad habit to teach new 
(Py)KDE coders.

Ciao,
Gordon





More information about the PyQt mailing list