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

Kaleb Pederson kaleb.pederson at gmail.com
Wed Jan 7 06:08:57 CET 2009


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



More information about the Qt-interest-old mailing list