[Qt-interest] remove buttons from a QVBoxLayout
Rohan McGovern
rohan.mcgovern at NOKIA.COM
Mon May 17 09:44:38 CEST 2010
On Monday 17 May 2010, Rohan McGovern wrote:
> On Monday 17 May 2010, ext Tamas Nagy wrote:
> > Hello!
> >
> > It compiles, but it causes segmentation fault.
> >
> > for(int i = 0; i < verticalbox->count(); i++)
> > verticalbox->takeAt(i)->widget()->setVisible(false);
>
> That code is wrong... you're removing items from the list while
> iterating over it. You want something more like:
>
> while (verticalbox->count()) {
> verticalbox->takeFirst()->...
> }
I didn't read the next lines of the message where you had something
just like this :-)
You also shouldn't use the return value of widget() without checking
for 0 first.
--
Rohan
More information about the Qt-interest-old
mailing list