[Qt-interest] connect()ing multiple buttons to a receiver

Malyushytsky, Alex alex at wai.com
Wed Jan 7 23:31:36 CET 2009


>> but I still don't know of how to tell
*which* button it points to at that point.

sender() gives you a pointer to your button.

If this slot can be invoked only from clicking on QButton you could:

if ( sender() )
{
QButton* b = (QButton*) sender();
 .....

}

Regards,
    Alex


-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Paul England
Sent: Tuesday, January 06, 2009 9:36 PM
Cc: qt-interest at trolltech.com
Subject: Re: [Qt-interest] connect()ing multiple buttons to a receiver

Hi

I know about QObject::sender(), but I still don't know of how to tell
*which* button it points to at that point.  I'll check out
QSignalMapper.  I recall using this a while back (vaguely).

 >> QButtonGroup

Doesn't this require the buttons to be in a group?  Like in a box?
That's not going to work in this case, unfortunately.

Cheers
Paul


Kaleb Pederson wrote:
> On Tue, Jan 6, 2009 at 8:55 PM, Paul England <pengland at cmt-asia.com> wrote:
>
>> To put this simply:
>>
>> I will have a few buttons (4 or 5) that I want to connect() to a single
>> receiver.
>> The receiver will behave slightly differently depending on what button
>> is pushed though (does the same thing on different data).
>>
>> The buttons are stored in an array, and are made in a loop.  How many
>> depends on an
>> environment variable.  I can connect() them to the receiver just fine,
>> but as they are in
>> an array, the receiver doesn't know which one was pushed.
>>
>
> Take a look at QSignalMapper.  I believe the example is almost exactly
> what you're discussing above.
>
> Also, take a look at QObject::sender().
>
>
>>  From what I remember, reimplementing event handlers is a nono.
>>
>
> Re-implementing event handlers is fine, under the appropriate
> conditions.  In this case, it's quite unnecessary.
>
> HTH,
>
> --Kaleb
>
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list