[Qt-interest] Multiple Button Problem

venkat reddy venkat.961 at gmail.com
Thu Aug 25 10:01:17 CEST 2011


Hi,

try the below code

connect below slot with all buttons.

void KeyPressed()
{
     QPushButton m_pclickedButton= qobject_cast<QPushButton *>(sender());
    if(m_pclickedButton){
       QString text=m_pclickedButton->text();
      }
}

On Thu, Aug 25, 2011 at 12:49 PM, Ankit Agarwal <ankit17.ag at gmail.com>wrote:

> Hi,
>
> I am using Qt4.2.2 on Linux, Fedora14
>
> I have a QWidget which has 15 buttons. Each button has a different text on
> it. My requirement is that, whenever a user clicks on a button, I need to
> popup an QMessageBox and show that text in the message box.
>
> Secondly, I have QList with 15 quint32 counter items. Each item in the list
> corresponds to each button in the QWidget. So, whenever a user click on one
> of the button, the corresponding counter item in the list should be
> incremented by 1.
>
> One way is to write 15 different connect statements, one for each button.
> But, I believe there should be a better way of doing the same thing.
>
> Please suggest how can I achieve this.
>
> --
> Regards,
> Ankit Agarwal
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
> --
Thanks&Regards,
Venkat Reddy pasya
Sling Media Pvt Ltd.
Bangalore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110825/395bf73c/attachment.html 


More information about the Qt-interest-old mailing list