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

John McClurkin jwm at nei.nih.gov
Sat Jun 20 22:12:48 CEST 2009


Ed Sutton wrote:
>> In your initial mail you asked whether it's possible to know the sender's
>> checked state from within a slot. Well, QObject::sender() tells you the
>> QObject that emitted the signal, so you could qobject_cast<> that to a
>> QRadioButton and check its state, and do whatever else you want to know
>> about the sender.
> 
> I had this part.  Probably made my question too wordy.
> 
>> But I might as well be misunderstanding your use-case right here :-)
> 
> 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?
> 
> -Ed
> 

>>>> I take it you are looking for QObject::sender()
>>>> (http://doc.trolltech.com/4.5/qobject.html#sender) ?
>>> I am not sure I understand.
>>>
>>> I can get the sender if I use the SLOT(channelChanged(QWidget*))
>>> signature.  How can QObject::sender() be used to associated the sender
>>> with my data object?
>>>
>>> Forgive for being slow.
>>>
>>> -Ed
>>>
Don't your QRadioButtons have labels or icons that indicate the new 
channel? You should be able to retrieve those from the pointer returned 
by sender() and associate the label or icon with your data object.



More information about the Qt-interest-old mailing list