tags:

views:

34

answers:

1

Hi.,

i am using Qwidget(parent). this parent widget contains lot of child widget. in the run time i need to clear all the child widgets from the parent.

How to do this? Please help me...

+2  A: 

You can use the following in your parent widget class:

QList<QWidget *> widgets = findChildren<QWidget *>();
foreach(QWidget * widget, widgets)
{
    delete widget;
}
Yulia Rogovaya
Thanks. it's working perfectly. Exactly i needed this.
saravanan
There is also a function provided by Qt called qDeleteAll, which takes a container and deletes every item in the container. So you could simplify this to qDeleteAll(findChildren<QWidget*>());
Caleb Huitt - cjhuitt