[Qt-interest] Multiple signals to one slot

Colin S. Miller no-spam-thank-you at csmiller.demon.co.uk
Sun Jan 31 14:14:40 CET 2010


Neville Dastur wrote:
> Hi
> 
> I have a group of checkboxes. Using the QSignalMapper I "connect" all of 
> them to a single member function
> 
> connect(ui->checkBoxDescriptionStatus_Current,
>    SIGNAL(stateChanged(int)),
>    m_signalMapperDescriptionFilters,
>    SLOT(map()));
> connect(ui->checkBoxDescriptionStatus_Retired,
>    SIGNAL(stateChanged(int)),
>    m_signalMapperDescriptionFilters,
>    SLOT(map()));
> 
<snip!>
> My problem now is how do a get the actual state of the checkbox that 
> fired the signal?

Neville,
You can use sender() in the slot. It will return, as a QObject*, the object
that the signal was sent for. Use
QCheckBox *firingBox = dynamic_cast<QCheckBox*>(sender());
to recover the checkbox that raised the signal.


(Of course, static_cast could be used as well)
HTH,
Colin S. Miller



More information about the Qt-interest-old mailing list