PDA

View Full Version : How to iterate through QButtonGroup's buttons?



gadnio
10th January 2006, 14:57
Hi there,
Does anyone know how can I easily iterate through QButtonGroup's buttons?

axeljaeger
10th January 2006, 15:34
Obtain a list of all childs of your QButtonGroup:

http://doc.trolltech.com/4.1/qobject.html#children

Have a for..each-loop iterate over all of them and check wether they are subclasses of QAbstractButton (Qt4) or QButton (Qt3) by using either qt_cast in Qt4 or http://doc.trolltech.com/4.1/qobject.html#inherits

wysota
10th January 2006, 15:35
And check their group() value.

gadnio
11th January 2006, 09:49
I've done it in a more clear way: every button I put in the button group I put also in a QPtrList. But that's as dumb as iterating all the children of the button group. I think it would be very good to have an iterator class for the QButtonGroup class.

wysota
11th January 2006, 09:54
...which would iterate over its children thus the effect would be the same and it would slow the code.

sunil.thaha
12th January 2006, 12:00
I don't get it
Doesn't the QButtonGroup have


QList<QAbstractButton *> QButtonGroup::buttons () const




QList<QAbstractButton *> list = buttonGroup->buttons();
...
foreach ( QAbstractButton *pButton, list){
// .......
}
// Check !!!
delete list; // Not Sure Please Check ??


wont't this Do ?

One More do we need to Delete the List ?

jacek
12th January 2006, 15:22
One More do we need to Delete the List ?How? It's not a pointer.

wysota
12th January 2006, 15:48
I don't get it
Doesn't the QButtonGroup have


QList<QAbstractButton *> QButtonGroup::buttons () const


wont't this Do ?


The question concerned Qt3 and not Qt4 (as you may notice in the header, the author uses Qt3 only) and QButtonGroup::buttons() is not present there.

sunil.thaha
13th January 2006, 06:06
There Again,
Some one forgets to See the Version :eek: