PDA

View Full Version : Which QCheckBox is checked?



Craig.Smith
8th November 2007, 21:18
I have a list of dynamically created QCheckBoxes as:


for (int d=0; d<5; ++d)
{
QCheckBox *checkBox = new QCheckBox(names[d], this);
sendToLayout->addWidget(checkBox);
connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(handleDestinationChange(int)));
}

I get the callback in the slot handleDestinationChange method. I want to do the same thing when each is checked, I just want to use the QString from checkBox->text() in the slot. The question is, how can I tell which of the 5 check boxes was the one that was checked? Only the check state is passed to the slot.

Thanks for any ideas.

Craig

jpn
8th November 2007, 21:32
You can use QSignalMapper or QObject::sender() to identify the sender.

Craig.Smith
9th November 2007, 14:52
Thanks! The QObject::sender() was exactly what I needed. It worked like a charm. :)