Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt4-preview-feedback Archive, May 2008
QMainWindow does not delete central widget properly


Message 1 in thread

Hi there,

I am trying to change the central widget of a QMainWindow when the user 
presses a button, but I am running into problems. Everytime I use the 
QMainWindow::setCentralWidget function, I get a warning that I am trying to 
delete a widget during it's event handling. This is ok with Qt buttons, 
because I just get the warning. However when I trigger the change from a 
custom widget (I am using Irrlicht to draw some 3D stuff), the whole 
application crashes. I think the crash is due to the fact that I try to delete 
the custom widget during the event loop too.

I think the problem is that when you set the central widget of QMainWindow, 
QMainWindow tries to delete the old widget using the delete command. 
However the QObject documentation claims that this is a bad thing to do and 
can lead to crashes, and so instead we should use QObject::deleteLeter(), 
which queues the object to be deleted outside of the loop.

So my question is: Is there a reason why QMainWindow uses delete instead of 
deleteLater(), or is this just a small oversight?

-- 
 [ signature omitted ]