[Qt-interest] How associate slot sender with my data object?
John McClurkin
jwm at nei.nih.gov
Sat Jun 20 22:01:28 CEST 2009
Ed Sutton wrote:
> I am getting started using signals and slots. I use QSignalMapper with QGroupBox collection of QRadioButtons that select video channels.
>
> In the received slot, how can I both retrieve the sender's checked state and associate the sender with it's related channel data object? Do QT widgets support a pointer to a void* "tag object"? Some way to associate my data object with the signal sender? I tried to make my own but cannot seem to derive from QRadioButton.
>
> In order to determine the QRadioButton checked state in the slot, the best choice seems to use the SLOT(channelChanged(QWidget*)) signature. In order to associate the sender with my data object, must I make my own associative map collection? Is this typical or is there a better approach?
>
> Thanks in advance for sharing your experience,
>
> -Ed
I don't think you can get the parameters of a signal using
QSignalMapper. If you need the id and the parameters of a set of signals
connected to a single slot, use the sender method.
MyWidget *w = qobject_cast<MyWidget *>?(sender());
if(w != (MyWidget *)NULL) {
}
It is important to use qobject_cast to verify that the sender of the
correct type.
More information about the Qt-interest-old
mailing list