PDA

View Full Version : Problem with delating main widget components (backtrace included)



mtrpoland
19th May 2007, 13:16
I've an application (~1500 lines of code) that crashes after trying to destroy my main widget(class's name is LibWin and is derivated directly from QWidget). Often when I order program to quit using qApp->quit() the window doesn't dissapear but it stays and doesn't respond to any clicking.

Here's backtrace from debugger:
#0 0xb7240a2f in free () from /lib/tls/i686/cmov/libc.so.6
#1 0xb73effc1 in operator delete () from /usr/lib/libstdc++.so.6
#2 0xb7be5119 in ~QComboBox (this=0x811c2b4) at widgets/qcombobox.cpp:1058
#3 0xb75cdea1 in QObjectPrivate::deleteChildren (this=0x812bdc8) at kernel/qobject.cpp:1823
#4 0xb7981649 in ~QWidget (this=0x811c3d4) at kernel/qwidget.cpp:1158
#5 0xb7c10791 in ~QGroupBox (this=0x811c3d4) at widgets/qgroupbox.cpp:189
#6 0x0805c426 in LibWin::~LibWin ()
#7 0x0805bfbe in main ()

could you suggest me a few possible reasons (maybe it is commonplace for newbie's to have their widgets undelated).

I may attach a whole project but it is quite heavy and I don't know whether any of you have enough time to scan the code.

Mike

jpn
19th May 2007, 13:21
Perhaps you try to delete something which has already been deleted? You know, a QObject (http://doc.trolltech.com/4.2/qobject.html#dtor.QObject) automatically deletes it's children. Also, you should not accidentally delete any objects allocated on the stack (the main window?).

wysota
19th May 2007, 13:54
Most often you can create the main window object on the stack in your main() method so that it is destroyed automatically when it goes out of scope (when main() returns). This way you don't have to care about deleting it.

marcel
19th May 2007, 14:02
I may attach a whole project but it is quite heavy and I don't know whether any of you have enough time to scan the code.
Attach only the destructor of LibWin.

marcel
19th May 2007, 14:10
Most often you can create the main window object on the stack in your main() method so that it is destroyed automatically when it goes out of scope (when main() returns). This way you don't have to care about deleting it.

But this is what he did. Just look at the trace.
Delete would have been in the trace if he had called "delete libwin;".

Anyway, most likely jpn is right - that QComboBox has been deleted somewhere else.

Regards