[Qt-interest] How associate slot sender with my data object?

Martin Gebert martin.gebert at alpha-bit.de
Mon Jun 22 10:40:55 CEST 2009


> The key to the question is how can I also associate the sender with an instance of MyObject?  
>
> Must I make an external stl map collection or is there a more "QT" like way?
>
>   

A map<QRadioButton*, MyObject*> (use QMap instead of std::map) would be
one solution. The other one would be to use the QSignalMapper and set up
a mapping for each radio button to the appropriate MyObject (BTW,
shouldn't that be named MyClass?). Your slot then reads

channelChanged(MyObject*)

and you get both your object and by using sender() the associated
button. Note that MyObject has to be derived from QObject for this.
Is this what you intended?

Martin



More information about the Qt-interest-old mailing list