[Gambas-user] What happens on a form close event

Benoît Minisini gambas at ...1...
Tue Sep 1 10:34:03 CEST 2009


> I was just doing some work where I wanted to get access to the tag:
>
>
> me.parent.parent
>
>  and found that though, at the start of loading the form that it exists
> (obviously) but that as soon as Form_close() is called that whearas the
> object me still exists until the form actually is destroyed, that 
> me.parent  = null. (hence no parent.parent)
>
> Can anyone explain the closing sequence, and can one get to the bit of data
> I want, from within form_close but before thet data is destroyed?
>
> Regards
>
> Richard
>

On real top-level windows, the Close event is raised when you call the Close 
method or when you click on the window manager close button. The window fully 
exists at the moment.

On embedded top-level windows, the Close event is called when the window is 
destroyed. Then you may have problems, as there is no way to know precisely 
when it happens - It depends on the toolkit. The window still exists, but its 
children or parents may not, depending on what indirectly is responsible of 
the closing.

I have just fixed a bug in Gambas 3 that made things crash in that last case. 
I'm not sure for Gambas 2, and I'm not sure everything is safe in Gambas 3 
now.

The reason is the following: Qt destroys the children of a parent widget (a 
container) *before* Gambas can see it. And the Close event of embedded windows 
is called when they are destroyed. So there is a moment when the situation is 
not coherent: Gambas think the widget exists whereas it does not. That can 
lead to crashes...

Regards,

-- 
Benoît




More information about the User mailing list