Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Many PushButton
Forum Updated to NodeBB v4.3 + New Features

Many PushButton

Scheduled Pinned Locked Moved General and Desktop
7 Posts 6 Posters 5.4k 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.
  • K Offline
    K Offline
    krisztiantobias
    wrote on last edited by
    #1

    Hello, how can i to make this easier and shorter?
    I have many PushButton (more then 100) and doing similar thing.

    public slots:
    @
    void MyForm::on_pb_1_clicked() { Methode(pb_1, Array[0]);}
    void MyForm::on_pb_2_clicked() { Methode(pb_2, Array[1]);}
    .
    .
    .
    void MyForm::on_pb_n_clicked() { Methode(pb_n, Array[n-1]);}
    @

    pb_1, .... pb_n is many pushbutton.

    Edit: please use code tags, Andre

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      QSignalMapper!

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stukdev
        wrote on last edited by
        #3

        Example:
        @
        QSignalMapper *btnGroup;
        btnGroup = new QSignalMapper(this);
        connect(btnGroup, SIGNAL(mapped(int)), this, SIGNAL(btnOutClickSlot(int)));

        void myclass::btnOutClickSlot(int btn)
        {
        //code here
        }

        QPushButton *tmp[2] = {pushButton,pushButton_2};
        for (quint16 i = 0; i < 2; i++)
        {
        btnGroup->setMapping(pushB[i], i);
        connect(tmp[i], SIGNAL(clicked()), btnGroup, SLOT(map()));
        }
        @

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dialingo
          wrote on last edited by
          #4

          You can use sender() inside slots to find out who sent the signal.
          @
          void MyForm::on_pb_any_clicked()
          {
          if(sender() == pb_1)
          Methode(pb_1, Array[0]);
          if(sender() == pb_2)
          Methode(pb_2, Array[0]);
          .....
          ......
          }
          @

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            I highly recommend using QSignalMapper instead of using sender().

            1 Reply Last reply
            0
            • K Offline
              K Offline
              krisztiantobias
              wrote on last edited by
              #6

              QSignalMapper is a perfect solution. TY!

              1 Reply Last reply
              0
              • B Offline
                B Offline
                BasicPoke
                wrote on last edited by
                #7

                It's a perfect solution except figuring out how to use it.
                Ron

                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