PDA

View Full Version : Enumerate



giusepped
4th November 2008, 06:43
Is it possible to enumerate the gourpBox object?
That is , I would like to meake a loop which iterate over all the object of a goupBox, an I need the goupBox object's count.

pgorszkowski
4th November 2008, 07:19
I am not sure is it what you want but check children function. It returns a list of all children so you can in easy way to find out how many objects your groupbox has.

pgorszkowski
4th November 2008, 07:37
Here you are an example code:



QGroupBox *groupBox = new QGroupBox(tr("E&xclusive Radio Buttons"));
groupBox->setCheckable(true);
groupBox->setChecked(false);
QRadioButton *radio1 = new QRadioButton(tr("Rad&io button 1"));
QRadioButton *radio2 = new QRadioButton(tr("Radi&o button 2"));
QRadioButton *radio3 = new QRadioButton(tr("Radio &button 3"));
radio1->setChecked(true);
QCheckBox *checkBox = new QCheckBox(tr("Ind&ependent checkbox"));
checkBox->setChecked(true);

QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(radio1);
vbox->addWidget(radio2);
vbox->addWidget(radio3);
vbox->addWidget(checkBox);
vbox->addStretch(1);
groupBox->setLayout(vbox);

const QList<QObject*> children = groupBox->children();

qDebug() << "Number of children: " << children.count();

for(QList<QObject*>::const_iterator cit = children.begin();
cit != children.end();++cit)
{
qDebug() << "Child: " << (*cit)->metaObject()->className();
}

giusepped
4th November 2008, 10:23
Thank you very much. I will try it.
G