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. creating signals with button slots

creating signals with button slots

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 472 Views
  • 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.
  • S Offline
    S Offline
    shravan_121
    wrote on last edited by
    #1

    I have a Button : Button *plus = createButton(tr("+"), SLOT(additiveOperatorClicked())); in which the additiveoperatorclicked is a function I have to create signal slot connection can it be made.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Yes, but you'll need to add a pointer to the object that has the slot as additional parameter to the createButton function, because that's needed for the connect call.

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

        @Chris-Kawa can you please explain me how to do that because i am in the learning phase.

        Chris KawaC 1 Reply Last reply
        0
        • S Offline
          S Offline
          shravan_121
          wrote on last edited by
          #4

          can you please explain me how to do that because i am in the learning phase.

          Pl45m4P 1 Reply Last reply
          0
          • S shravan_121

            can you please explain me how to do that because i am in the learning phase.

            Pl45m4P Online
            Pl45m4P Online
            Pl45m4
            wrote on last edited by
            #5

            @shravan_121

            If you want to connect your plus button to your additiveOperatorClicked function:

            connect(plus, SIGNAL(clicked()), this, SLOT(additiveOperatorClicked()));
            
            

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            4
            • S shravan_121

              @Chris-Kawa can you please explain me how to do that because i am in the learning phase.

              Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @shravan_121 Well, assuming your Button class has a clicked() signal you can do something like this:

              Button* createButton(const QString& text, QObject* obj, const char* slot)
              {
                  Button* button = new Button(text);
                  QObject::connect(button, SIGNAL(clicked()), obj, slot);
                  return button;
              }
              

              and assuming you have some_object that has a additiveOperatorClicked() slot you can use it like this:

              Button* plus = createButton("+", some_object, SLOT(additiveOperatorClicked()));
              
              1 Reply Last reply
              5

              • Login

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