[Qt-interest] QVBox removeItem

Oszkar Ambrus oszkar.ambrus at deri.org
Sat May 15 20:01:04 CEST 2010


Hi,
> I have Qt 4.6, and i want to remove all children of the widget.
> I would like to write a Clear() function.
> 
> If i switch the array to dynamically allocated, so i use
> QList<QPushButton*> buttons = new QList<QPushButton*>
> 
> These buttons are added to the QVBox.
> 
> And i try removeItem which is not documented on the Qt website.
> 
> while(vbox->children->count())
> {
>     vbox->removeItem(0);
> }
> 
> Is it correct?

It is strongly advised to use QVBoxLayout, not Q3VBox.

Then you can write:
while( layout->count() ) {
     layout->removeItem( layout->itemAt(0) );
}

Of course you have to watch for memory leaks, that is to properly delete 
those widgets if they have no parent.


Regards,
-- 
Oszkár Ambrus

"Whoever believes in the Son [Jesus Christ] has eternal life"
(John 3:36)

Masters Student, Digital Enterprise Research Institute, NUIG
[http://www.deri.ie]




More information about the Qt-interest-old mailing list