How to use for loop to check multiple number of objects
Hi,
I have created 32 chechkboxes in one of my program and given unique name for each object by incrementing the value of 1,i.e name of 1st checkbox is ch_1 and 2nd checkbox is ch_2 and so on.
I want to check weather all the checkboxes were selected or not by using for loop is it possible to use the for loop.If there is a chance please help me
Thanks in advance,
Rohith.G
Re: How to use for loop to check multiple number of objects
Create a list or vector with the pointers of these checkboxes and iterate over that container.
Or use QObject::findChildren() on a common ancestor with a regular expression matching your name definitions (assuming those are the checkboxes' QObject names)
Cheers,
_
Re: How to use for loop to check multiple number of objects
Hi Anda_skoa,
First of all thanks for replying for me i have tried by following your guidance,but i was not able to execute i may done wrong some where.
I have created the checkboxes in the Qt creator and when i am trying to use the find children by using the following statement written below
QCheckBox *box = parentWidget->findChild<QCheckBox *>("ch_1");
But while compiling this is producing error
"error: invalid use of member (did you forget the '&' ?)
error: base operand of '->' is not a pointer"
Please guide me
Thanks & Regards,
Rohith.G
Re: How to use for loop to check multiple number of objects
Do you have a variable called "parentWidget"?
Or are you trying to use QWidget::parentWidget() and forgot the parentheses?
And just to be sure: you are aware that findChild() will only retrieve one widget, right?
That you could directly access via the "ui" pointer.
Cheers,
_
Re: How to use for loop to check multiple number of objects
Hi anda_skoa,
I have tried the method that was said by you i.e by using the QList but i am unable to store the objects of QCheckBox in to it,I may have done wrong while impletion.
If it is possible can you please provice me the sample code for storing objects of an QCheckBox into a list.
Thanks & Regards,
Rohith.G
Re: How to use for loop to check multiple number of objects
Quote:
Originally Posted by
gunturrohith
I have tried the method that was said by you i.e by using the QList but i am unable to store the objects of QCheckBox in to it,I may have done wrong while impletion.
Hard to tell, you forgot to post the code you have.
Quote:
Originally Posted by
gunturrohith
If it is possible can you please provice me the sample code for storing objects of an QCheckBox into a list.
Code:
QList<QCheckBox*> list;
list << checkbox;
Cheers,
_