[Qt-interest] Multiple signals to one slot
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Mon Feb 1 02:00:28 CET 2010
Hi Neville,
I would suggest to use QButtonGroup instead of QSignalMapper on
QAbstractButton derivatives - much easier and it does the reverse lookups as
well (see button(int id) function).
Tony
> -----Original Message-----
> Thank you, but I needed the mapped int to still be passed. I
> suppose I
> could set a userdata for each checkbox to carry this, but after some
> futher reading I found that you can get the object from the
> mapped id.
> So I now do:
>
> QCheckBox *cb = qobject_cast<QCheckBox
> *>(m_signalMapperConceptFilters->mapping(i));
>
> and I have my QCheckBox widget as well as the map int
>
> Andreas Pakulat wrote:
> > On 30.01.10 20:09:41, 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()));
> >>
> >> etc ...
> >>
> >> I use the setMapper to specify a int for each checkbox
> >>
> >>
> m_signalMapperDescriptionFilters->setMapping(ui->checkBoxDescr
> iptionStatus_Current,
> >> NBD::ND_SNOMED_DESCRIPTIONSTATUS_Current);
> >>
> m_signalMapperDescriptionFilters->setMapping(ui->checkBoxDescr
> iptionStatus_Retired,
> >>
> >> NBD::ND_SNOMED_DESCRIPTIONSTATUS_Retired);
> >>
> >> and finally connect the whole thing together with:
> >> connect(m_signalMapperDescriptionFilters,
> >> SIGNAL(mapped(int)),
> >> this,
> >> SLOT(map_DescriptionStatusFilterChange(int)));
> >>
> >> My problem now is how do a get the actual state of the
> checkbox that
> >> fired the signal?
> >>
> >
> > Either store a map of int->QCheckBox, or use the QWidget* version of
> > setMapping to transport the checkbox, then you can simply
> cast it in the
> > slot.
> >
> > Andreas
> >
> >
More information about the Qt-interest-old
mailing list