[Qt-interest] Multiple SIGNAL connected to single SLOT andsender() function

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Wed Nov 11 08:51:36 CET 2009


Or QButtonGroup which is much easier.  
 
In constructor:
    group.addButton( ui.button1, 1 );
    group.addButton( ui.button2, 2 );
    ...
    connect( &group, SIGNAL(buttonClicked(int)), SLOT(buttonHandler(int)));
 
The slot:
 
void myDialog::buttonHandler(int buttonId)
{
    QAbstractButton *btn = group.button(buttonId);
    if (btn)
    {
        // Set button properties...    or
        // switch(buttonId) ...
    }
}
 
Tony.
 
 

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of André Somers
Sent: Wednesday, 11 November 2009 17:58
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Multiple SIGNAL connected to single SLOT andsender() function



You can do that by casting. This is a basic C++ thing, by the way. There are different types of cast available, Google will inform you on those. One notable one though is provided by Qt itself: qobject_cast. You may use it.

 

However:

There is a better way to do what you want. Take a look at QSignalMapper.

 

André

 

 

Van: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] Namens Sambhav
Verzonden: dinsdag 10 november 2009 16:46
Aan: qt-interest at trolltech.com
Onderwerp: [Qt-interest] Multiple SIGNAL connected to single SLOT and sender() function

 

Hi,

 

I want to connect multiple QPushButton(s) to a single SLOT. In the SLOT it is required to change the certain properties of the Button. I checked the documentation and found this under signal and slots page. 

 

Advanced Signals and Slots Usage

For cases where you may require information on the sender of the signal, Qt provides the  <https://mail.google.com/mail/html/compose/static_files/qobject.html#sender> QObject::sender() function, which returns a pointer to the object that sent the signal.

 

I want to know how to convert the QObject returned by the sender function to the QPushButton object.

 

Thanks and Regards,

Sambhav 



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4594 (20091111) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091111/430c1919/attachment.html 


More information about the Qt-interest-old mailing list