Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED]QPushButton Signal connection
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QPushButton Signal connection

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 5 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dreamerindia
    wrote on last edited by
    #1

    Hi all,

    Is there is any method to connect the all QPushbuttons used in the project to same slot. instead of writing connect statement for individual QpushButtons?

    Instead of,
    @ connect(ui->continuousBut,SIGNAL(pressed()),this,SLOT(Beep()));
    connect(ui->continuousBut,SIGNAL(released()),this,SLOT(Mute()));

    connect(ui->GateBut,SIGNAL(pressed()),this,SLOT(Beep()));
    connect(ui->GateBut,SIGNAL(released()),this,SLOT(Mute()));
    
    connect(ui->singleBut,SIGNAL(pressed()),this,SLOT(Beep()));
    connect(ui->singleBut,SIGNAL(released()),this,SLOT(Mute()));
    
    connect(ui->burstBut,SIGNAL(pressed()),this,SLOT(Beep()));
    connect(ui->burstBut,SIGNAL(released()),this,SLOT(Mute()));
    
    connect(ui->MANBut,SIGNAL(pressed()),this,SLOT(Beep()));
    connect(ui->MANBut,SIGNAL(released()),this,SLOT(Mute()));
    
    connect(ui->INTBut,SIGNAL(pressed()),this,SLOT(Beep()));
    connect(ui->INTBut,SIGNAL(released()),this,SLOT(Mute()));
    
    connect(ui->EXTBut,SIGNAL(pressed()),this,SLOT(Beep()));
    connect(ui->EXTBut,SIGNAL(released()),this,SLOT(Mute()));@
    

    something like,

    @connect(ui->QPushButton,SIGNAL(pressed()),this,SLOT(Beep()));
    connect(ui->QPushButton,SIGNAL(released()),this,SLOT(Mute()));@

    ~Ravivarman~

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      there is an "auto connect feature":http://qt-project.org/doc/qt-4.8/qmetaobject.html#connectSlotsByName in Qt, which connects objects with a slot automatically.
      But i requires to set the "object name":http://qt-project.org/doc/qt-4.8/qobject.html#objectName-prop. But i don't know if this is possible when using ui-Files (never used them yet)... If it's possible to set a different QObject-objectname than the object name in the ui file to identify the object then you can try using this method.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #3

        ... or create "QButtonGroup":http://qt-project.org/doc/qt-5.0/qtwidgets/qbuttongroup.html, add all buttons in it and connect one of the QButtonGroup::buttonClicked signal to your slot

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          There's also findChildren and you loop over the button list to connect them. That is unless you have other push buttons on the same UI. In this case you should give a name to these buttons to use findChildren

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dreamerindia
            wrote on last edited by
            #5

            thanks friends.

            QButtonGroup is what i want.thank you.

            ~Ravivarman~

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tabi
              wrote on last edited by
              #6

              You can do this aslo:
              @void ButtonGroup1Slot()
              {
              if(sender()->objectName().contains("Button1"))
              {
              //do this and so on for other buttons
              }
              //perform similar operations here
              }@

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved