Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, April 2001
WG: widget-destructor


Message 1 in thread

To trolls and qt-users:

in QWidget::~QWidget() why

    if ( childObjects ) {			// delete children objects
      QObject* obj;
	QObjectListIt it(*childObjects);
	QObject *obj;
	while ( (obj=it.current()) ) {
	    ++it;
	    obj->parentObj = 0;
	    // ### nest line is a QGList workaround - remove in 3.0
	    childObjects->removeRef( obj );
	    delete obj;
	}

and not

   if ( childObjects ) {			// delete children objects
      QObject* obj;
      while( obj= childObjects->first() ) delete obj;
   }

???

That would solve the
parentless-non-toplevel-widget-during-destruction-problem because that's the
origin of the problem.

bye
Daniel

-----Ursprungliche Nachricht-----
Von: porten@trolltech.com [mailto:porten@trolltech.com]Im Auftrag von
Harri Porten
Gesendet: Mittwoch, 18. April 2001 16:34
An: rolf@finecode.de
Betreff: Re: widget-destructor


> Daniel Rolf wrote:
>
> Hello,
>
> I've got a problem:
> the intermediate state if a widget is being destroyed is fatal for me:
>
> if a widget is destroyed it destroys all its child-widgets by setting
> their parent to 0 and the deleting them. This is fatal because setting
> the parent to 0 will set the widget to a contradictive state because
> it's not a top-level-widget.
> qt calls my destructor and I call some internal code which results to
> some gp if calling setEnabled(FALSE) because the widget is not
> toplevel neither it has a parent (anymore):
>
> void QWidget::setEnabled( bool enable )
> {...
>     if ( !isTopLevel() && !parentWidget()->isEnabled() && enable
> )
>                    <----- here it fails because isTopLevel returns NO
> and parentWidget returns NULL
> ...
> }
>
> any idea? that should be fixed in the widget-destructor!!!!!!!!

Yes.Please try the attached patch.

But why do you call setEnabled() inside of a widget being destructed ?
:)

Harri.

==== //depot/qt/2.3/src/kernel/qwidget.cpp#1 (text) -
//depot/qt/2.3/src/kernel/qwidget.cpp#2 (text) ==== content
@@ -1266,7 +1266,8 @@
     else
 	setWState( WState_ForceDisabled );

-    if ( !isTopLevel() && !parentWidget()->isEnabled() && enable )
+    if ( !isTopLevel() && parentWidget() &&
+	 !parentWidget()->isEnabled() && enable )
 	return; // nothing we can do

     if ( enable ) {


Message 2 in thread

Daniel Rolf wrote:
> 
> To trolls and qt-users:
> 
> in QWidget::~QWidget() why
> 
>     if ( childObjects ) {                       // delete children objects
>       QObject* obj;
>         QObjectListIt it(*childObjects);
>         QObject *obj;
>         while ( (obj=it.current()) ) {
>             ++it;
>             obj->parentObj = 0;
>             // ### nest line is a QGList workaround - remove in 3.0
>             childObjects->removeRef( obj );
>             delete obj;
>         }
> 
> and not
> 
>    if ( childObjects ) {                        // delete children objects
>       QObject* obj;
>       while( obj= childObjects->first() ) delete obj;
>    }
> 
> ???

Setting the parent object of a to be destructed widget to 0 makes a lot
of sense. You neither want the child to call any functions of the parent
which is about to destruct itself nor send it any events.
 
> That would solve the
> parentless-non-toplevel-widget-during-destruction-problem because that's the
> origin of the problem.

Did the patch I send to you work, i.e. prevent the crash ?

Harri.


Message 3 in thread

Harri,

the patch works. But there are some more places where to attach the patch.

bye
Daniel

-----Ursprungliche Nachricht-----
Von: owner-qt-interest@trolltech.com
[mailto:owner-qt-interest@trolltech.com]Im Auftrag von Harri Porten
Gesendet: Freitag, 20. April 2001 03:52
An: rolf@finecode.de
Cc: qt-interest@trolltech.com
Betreff: Re: WG: widget-destructor


Daniel Rolf wrote:
>
> To trolls and qt-users:
>
> in QWidget::~QWidget() why
>
>     if ( childObjects ) {                       // delete children objects
>       QObject* obj;
>         QObjectListIt it(*childObjects);
>         QObject *obj;
>         while ( (obj=it.current()) ) {
>             ++it;
>             obj->parentObj = 0;
>             // ### nest line is a QGList workaround - remove in 3.0
>             childObjects->removeRef( obj );
>             delete obj;
>         }
>
> and not
>
>    if ( childObjects ) {                        // delete children objects
>       QObject* obj;
>       while( obj= childObjects->first() ) delete obj;
>    }
>
> ???

Setting the parent object of a to be destructed widget to 0 makes a lot
of sense. You neither want the child to call any functions of the parent
which is about to destruct itself nor send it any events.

> That would solve the
> parentless-non-toplevel-widget-during-destruction-problem because that's
the
> origin of the problem.

Did the patch I send to you work, i.e. prevent the crash ?

Harri.

--
 [ signature omitted ]