PDA

View Full Version : Many checkboxes and one slot



mirelon
2nd April 2010, 10:55
hi,
i have many checkboxes on a dialog (checkBox1, checkBox2, checkBox3...)
I also store pointers to them in a qlist:


QList<QCheckBox* > checkBoxes;

When i change state of one of them, I want to call a function checking().
I do it this way:


for(int i=0;i<checkBoxes.size();i++)
connect(checkBoxes[i],SIGNAL(clicked()),this,SLOT(checking()));

It is ok, but what should I do to know which checkBox was clicked inside checking() slot?
I really don't want to have a slot for each checkBox...

Lykurg
2nd April 2010, 10:57
You can use QObject::sender() or better use QSignalMapper.

wysota
2nd April 2010, 11:22
For check boxes I'd suggest to use the signal toggled() instead of clicked(), it gives you some more information.

ness
2nd April 2010, 12:48
Maybe this could some help for you,
http://qt.nokia.com/doc/4.6/qbuttongroup.html

kavitha.M
17th May 2013, 07:18
HI ,

I am newly working with QT .

i am implementing a list of CheckBox in which i need to write signal and slot . The ctrls are dynamicaly generated based on required count.


pls send me code if available. on check of checkbox i need to know which checkbox i have checked ...if i get the interger as return fine.

first checkbox as -"1"
first checkbox as -"2"
first checkbox as -"3"

how i can do it ..pls help me ...

wysota
17th May 2013, 07:42
If only one box can be checked at the same time then place all of them into a QButtonGroup and use API of the latter to learn which of the buttons is checked. And optionally use QRadioButton instances instead of QCheckBox.