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. additional arguments to slot

additional arguments to slot

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 196 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.
  • O Offline
    O Offline
    over9000
    wrote on last edited by over9000
    #1

    Hi

    I am struggling to get a grasp of how do this. I understand basic signal/slot architecture but cannot apply it to my use case.

    I have a QWidget which displays certain information. The QWidget has a QPushButton. On clicking that button, I want to call some of my application (not-QT) functions and then display that in a display box.

    I can of course call a plain function as follows:

    void handleButton()
    {
    
    }
    
    QObject::connect(&button, &QPushButton::clicked, &handleButton);
    

    But the "handleButton" function which I need to call takes many arguments (all of which will remain the same every time the button is clicked and not Qt related objects).

    How can I achieve this?

    Thanks

    Chris KawaC 1 Reply Last reply
    0
    • O over9000

      Hi

      I am struggling to get a grasp of how do this. I understand basic signal/slot architecture but cannot apply it to my use case.

      I have a QWidget which displays certain information. The QWidget has a QPushButton. On clicking that button, I want to call some of my application (not-QT) functions and then display that in a display box.

      I can of course call a plain function as follows:

      void handleButton()
      {
      
      }
      
      QObject::connect(&button, &QPushButton::clicked, &handleButton);
      

      But the "handleButton" function which I need to call takes many arguments (all of which will remain the same every time the button is clicked and not Qt related objects).

      How can I achieve this?

      Thanks

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

      @over9000 When something emits a signal the arguments are routed to the slot, so it has to have the same or fewer number of arguments and they need to have matching type. If you don't care about the signal's arguments and want to call your slot with a fixed set of arguments you can wrap it in another function or a lambda:

      void handleButton(int foo, const QString& bar) { ... }
      
      QObject::connect(&button, &QPushButton::clicked, [&](){ handleButton(42, "hello"); });
      
      O 1 Reply Last reply
      3
      • Chris KawaC Chris Kawa

        @over9000 When something emits a signal the arguments are routed to the slot, so it has to have the same or fewer number of arguments and they need to have matching type. If you don't care about the signal's arguments and want to call your slot with a fixed set of arguments you can wrap it in another function or a lambda:

        void handleButton(int foo, const QString& bar) { ... }
        
        QObject::connect(&button, &QPushButton::clicked, [&](){ handleButton(42, "hello"); });
        
        O Offline
        O Offline
        over9000
        wrote on last edited by
        #3

        @Chris-Kawa brilliant, many thanks

        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