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. How to connect to a slot with multiple arguments
QtWS25 Last Chance

How to connect to a slot with multiple arguments

Scheduled Pinned Locked Moved Unsolved General and Desktop
slotconnectsignalmappersignal & slot
13 Posts 4 Posters 7.6k 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.
  • C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 19 Dec 2019, 09:51 last edited by
    #2

    @hobbyProgrammer said in How to connect to a slot with multiple arguments:

    Is there anyone who knows how to do this?

    And what should the second parameter be?
    Using the old signal/slot syntax you can set the second parameter as a default parameter. Using the new signal/slot syntax you can use a lambda.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    H 2 Replies Last reply 19 Dec 2019, 09:52
    3
    • C Christian Ehrlicher
      19 Dec 2019, 09:51

      @hobbyProgrammer said in How to connect to a slot with multiple arguments:

      Is there anyone who knows how to do this?

      And what should the second parameter be?
      Using the old signal/slot syntax you can set the second parameter as a default parameter. Using the new signal/slot syntax you can use a lambda.

      H Offline
      H Offline
      hobbyProgrammer
      wrote on 19 Dec 2019, 09:52 last edited by
      #3

      @Christian-Ehrlicher Hi,
      the first and second arguments are integers.

      mySlot(int, int);

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 19 Dec 2019, 09:55 last edited by
        #4

        @hobbyProgrammer said in How to connect to a slot with multiple arguments:

        the first and second arguments are integers.

        I did not ask for the data type, I ask what value you want to pass... and I already gave you the answer on how to achieve it.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        H 1 Reply Last reply 19 Dec 2019, 09:56
        0
        • C Christian Ehrlicher
          19 Dec 2019, 09:55

          @hobbyProgrammer said in How to connect to a slot with multiple arguments:

          the first and second arguments are integers.

          I did not ask for the data type, I ask what value you want to pass... and I already gave you the answer on how to achieve it.

          H Offline
          H Offline
          hobbyProgrammer
          wrote on 19 Dec 2019, 09:56 last edited by
          #5

          @Christian-Ehrlicher oh alright. The first argument is an ID that is the result of a QSqlQuery. The second argument is a simple 1, 2 or 3 (depends on which signal is triggered).

          1 Reply Last reply
          0
          • C Christian Ehrlicher
            19 Dec 2019, 09:51

            @hobbyProgrammer said in How to connect to a slot with multiple arguments:

            Is there anyone who knows how to do this?

            And what should the second parameter be?
            Using the old signal/slot syntax you can set the second parameter as a default parameter. Using the new signal/slot syntax you can use a lambda.

            H Offline
            H Offline
            hobbyProgrammer
            wrote on 19 Dec 2019, 10:18 last edited by
            #6

            @Christian-Ehrlicher said in How to connect to a slot with multiple arguments:

            Using the old signal/slot syntax you can set the second parameter as a default parameter.

            I am using the old signal/slot syntax. But how do I set the second parameter as a default parameter?
            Do you have example code?

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 19 Dec 2019, 10:38 last edited by
              #7

              @hobbyProgrammer said in How to connect to a slot with multiple arguments:

              Do you have example code?

              Really C++ basics: https://en.cppreference.com/w/cpp/language/default_arguments

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              H 1 Reply Last reply 19 Dec 2019, 15:01
              3
              • C Christian Ehrlicher
                19 Dec 2019, 10:38

                @hobbyProgrammer said in How to connect to a slot with multiple arguments:

                Do you have example code?

                Really C++ basics: https://en.cppreference.com/w/cpp/language/default_arguments

                H Offline
                H Offline
                hobbyProgrammer
                wrote on 19 Dec 2019, 15:01 last edited by hobbyProgrammer
                #8

                @Christian-Ehrlicher

                MainWindow.h:

                private slots:
                    void setStatus(int, int);
                

                MainWindow.cpp:

                void MainWindow::connectActions()
                {
                        connect(value, SIGNAL(statusSafe()), signalMapper, SLOT(map()));
                        signalMapper->setMapping(values, ID);
                        connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(setStatus(int, 1)));
                }
                
                void MainWindow::setStatus(int id, int status)
                {
                //some code
                }
                

                this combination still gives me this error:

                QObject::connect: No such slot MainWindow::setStatus(int, 1) in ..\..\..\Documents\QtProject\mainwindow.cpp:67
                QObject::connect:  (receiver name: 'MainWindow')
                
                C 1 Reply Last reply 19 Dec 2019, 15:27
                0
                • H hobbyProgrammer
                  19 Dec 2019, 15:01

                  @Christian-Ehrlicher

                  MainWindow.h:

                  private slots:
                      void setStatus(int, int);
                  

                  MainWindow.cpp:

                  void MainWindow::connectActions()
                  {
                          connect(value, SIGNAL(statusSafe()), signalMapper, SLOT(map()));
                          signalMapper->setMapping(values, ID);
                          connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(setStatus(int, 1)));
                  }
                  
                  void MainWindow::setStatus(int id, int status)
                  {
                  //some code
                  }
                  

                  this combination still gives me this error:

                  QObject::connect: No such slot MainWindow::setStatus(int, 1) in ..\..\..\Documents\QtProject\mainwindow.cpp:67
                  QObject::connect:  (receiver name: 'MainWindow')
                  
                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 19 Dec 2019, 15:27 last edited by
                  #9

                  @hobbyProgrammer Is it so hard reading the links I gave you?

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  H 1 Reply Last reply 19 Dec 2019, 15:46
                  2
                  • C Christian Ehrlicher
                    19 Dec 2019, 15:27

                    @hobbyProgrammer Is it so hard reading the links I gave you?

                    H Offline
                    H Offline
                    hobbyProgrammer
                    wrote on 19 Dec 2019, 15:46 last edited by
                    #10

                    @Christian-Ehrlicher yes I don't really seem to understand it.

                    is this what you meant by setting the default parameter?

                    void MainWindow::setStatus(int id, int status = 1)
                    {
                    //some code
                    }
                    

                    because that won't help me at all. I need the status to be variable. But different statusses have different signals so I thought that this might do the trick, but it didn't.

                    void MainWindow::connectActions()
                    {
                            connect(value, SIGNAL(statusSafe()), signalMapper, SLOT(map()));
                            signalMapper->setMapping(values, ID);
                            connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(setStatus(int, 1)));
                    }
                    
                    K 1 Reply Last reply 19 Dec 2019, 16:49
                    0
                    • C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 19 Dec 2019, 16:44 last edited by
                      #11

                      As I already told you:

                      Using the new signal/slot syntax you can use a lambda.

                      C++ basics (again)

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      0
                      • H hobbyProgrammer
                        19 Dec 2019, 15:46

                        @Christian-Ehrlicher yes I don't really seem to understand it.

                        is this what you meant by setting the default parameter?

                        void MainWindow::setStatus(int id, int status = 1)
                        {
                        //some code
                        }
                        

                        because that won't help me at all. I need the status to be variable. But different statusses have different signals so I thought that this might do the trick, but it didn't.

                        void MainWindow::connectActions()
                        {
                                connect(value, SIGNAL(statusSafe()), signalMapper, SLOT(map()));
                                signalMapper->setMapping(values, ID);
                                connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(setStatus(int, 1)));
                        }
                        
                        K Offline
                        K Offline
                        KroMignon
                        wrote on 19 Dec 2019, 16:49 last edited by
                        #12

                        @hobbyProgrammer said in How to connect to a slot with multiple arguments:

                        void MainWindow::setStatus(int id, int status = 1)
                        {
                        //some code
                        }

                        As @Christian-Ehrlicher told you, this is a C++ basic knowledge; I think you should start to learn C++ basics this will help you to avoid basic errors.

                        Default values for arguments are declared in the class declaration:

                        private slots:
                            void setStatus(int id , int status = 0);
                        

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        1 Reply Last reply
                        2
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 19 Dec 2019, 19:27 last edited by
                          #13

                          Hi,

                          Where do you get that ID ?

                          You'll click on the action, get the ID and then call the slot ?

                          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

                          11/13

                          19 Dec 2019, 16:44

                          • Login

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