PDA

View Full Version : QWidget delete at once



bunjee
14th February 2008, 14:09
I'm manipulating a lots of QWidget, but I also delete and replace them quite often.

I know that QT keeps a pool of QWidget, just in case they are reloaded again. Is there a way to really delete a QWidget at once?

marcel
14th February 2008, 14:34
There's no widget pool, just their parents that keep references to them.
To delete a widget just call QWidget::deleteLater(), and it will be deleted the next time the event loop gains control.

You can also call delete myWidget; but make sure to also make it null afterwards.

bunjee
14th February 2008, 14:43
So if I'm creating / deleting a large amount of QWidget and not getting back my memory there is an issue somewhere right ?

marcel
14th February 2008, 14:46
Make sure every widget has a parent(that way you know that when deleting a widget all its children will be also deleted) and then check for leaks somewhere else in your program.
You can use a profiler to get some idea about where exactly the leaks are occurring.