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. Error if I pass arguments to connect in
Forum Updated to NodeBB v4.3 + New Features

Error if I pass arguments to connect in

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 3.0k 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));

    gives me error Object::connect: No such slot GQActions::writeimage(QString("all"))
    Object::connect: No such slot GQActions::writeimage(QString("all"))

    but If I do not pass any argument in writeimage then I do not get error
    connect(act, SIGNAL(triggered()), this, SLOT(writeimage());

    it is working fine

    jsulmJ Pradeep KumarP 2 Replies Last reply
    0
    • Q Qt Enthusiast

      connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));

      gives me error Object::connect: No such slot GQActions::writeimage(QString("all"))
      Object::connect: No such slot GQActions::writeimage(QString("all"))

      but If I do not pass any argument in writeimage then I do not get error
      connect(act, SIGNAL(triggered()), this, SLOT(writeimage());

      it is working fine

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Qt-Enthusiast you can not pass parameters to slots in connect!
      Parameters are passed from signal when it is emitted.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4
      • Q Qt Enthusiast

        connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));

        gives me error Object::connect: No such slot GQActions::writeimage(QString("all"))
        Object::connect: No such slot GQActions::writeimage(QString("all"))

        but If I do not pass any argument in writeimage then I do not get error
        connect(act, SIGNAL(triggered()), this, SLOT(writeimage());

        it is working fine

        Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by Pradeep Kumar
        #3

        @Qt-Enthusiast

        As said by @jsulm ,

        connect(act, SIGNAL(triggered()), this, SLOT(writeimage()));
        both the signatures must be same.

        If you have any values to be passed, can provide only datatypes.

        Ex:
        connect(act, SIGNAL(triggered(bool)), this, SLOT(writeimage(bool)));

        Thanks,

        Pradeep Kumar
        Qt,QML Developer

        jsulmJ 1 Reply Last reply
        3
        • Pradeep KumarP Pradeep Kumar

          @Qt-Enthusiast

          As said by @jsulm ,

          connect(act, SIGNAL(triggered()), this, SLOT(writeimage()));
          both the signatures must be same.

          If you have any values to be passed, can provide only datatypes.

          Ex:
          connect(act, SIGNAL(triggered(bool)), this, SLOT(writeimage(bool)));

          Thanks,

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @Pradeep-Kumar @Qt-Enthusiast Actually the signal can have more parameters than the slot - the slot then just ignores all the other parameters.
          The thing is:

          connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));
          

          this is not a valid connect call as QString("currrent") creates a QString instance. If writeimage has a QString parameter then it should be:

          connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString)));
          

          but even then it is wrong as the signal does not have QString parameter.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          J.HilkJ 1 Reply Last reply
          4
          • jsulmJ jsulm

            @Pradeep-Kumar @Qt-Enthusiast Actually the signal can have more parameters than the slot - the slot then just ignores all the other parameters.
            The thing is:

            connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString("currrent"))));
            

            this is not a valid connect call as QString("currrent") creates a QString instance. If writeimage has a QString parameter then it should be:

            connect(act, SIGNAL(triggered()), this, SLOT(writeimage(QString)));
            

            but even then it is wrong as the signal does not have QString parameter.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @jsulm @Pradeep-Kumar @Qt-Enthusiast

            can pass a default parameters to the SIGNAL, to somewhat circumvent the issue

            signals:
               void signalDefault(QString s = "foo");
            
            private slots:
            void slotDefault(QString s){
             // do stuff
            }
            
            //in cpp
            connect(this, SIGNAL(signalDefault(QString)), this, SLOT(slotDefault(QString)));
            emit signalDefault();
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            jsulmJ Pradeep KumarP 2 Replies Last reply
            1
            • J.HilkJ J.Hilk

              @jsulm @Pradeep-Kumar @Qt-Enthusiast

              can pass a default parameters to the SIGNAL, to somewhat circumvent the issue

              signals:
                 void signalDefault(QString s = "foo");
              
              private slots:
              void slotDefault(QString s){
               // do stuff
              }
              
              //in cpp
              connect(this, SIGNAL(signalDefault(QString)), this, SLOT(slotDefault(QString)));
              emit signalDefault();
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @J.Hilk I never tried, did you?
              But even if it is working I wouldn't do this because you're hiding in your code what you actually pass to the connected slots.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              J.HilkJ 1 Reply Last reply
              1
              • J.HilkJ J.Hilk

                @jsulm @Pradeep-Kumar @Qt-Enthusiast

                can pass a default parameters to the SIGNAL, to somewhat circumvent the issue

                signals:
                   void signalDefault(QString s = "foo");
                
                private slots:
                void slotDefault(QString s){
                 // do stuff
                }
                
                //in cpp
                connect(this, SIGNAL(signalDefault(QString)), this, SLOT(slotDefault(QString)));
                emit signalDefault();
                
                Pradeep KumarP Offline
                Pradeep KumarP Offline
                Pradeep Kumar
                wrote on last edited by
                #7

                @J.Hilk ,

                can we use as u mentioned,

                signals:
                void signalDefault(QString s = "foo");

                and emit without argument?.

                emit signalDefault();

                Thanks,

                Pradeep Kumar
                Qt,QML Developer

                jsulmJ J.HilkJ 2 Replies Last reply
                1
                • Pradeep KumarP Pradeep Kumar

                  @J.Hilk ,

                  can we use as u mentioned,

                  signals:
                  void signalDefault(QString s = "foo");

                  and emit without argument?.

                  emit signalDefault();

                  Thanks,

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Pradeep-Kumar just try

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @J.Hilk I never tried, did you?
                    But even if it is working I wouldn't do this because you're hiding in your code what you actually pass to the connected slots.

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    @jsulm said in Error if I pass arguments to connect in:

                    @J.Hilk I never tried, did you?
                    But even if it is working I wouldn't do this because you're hiding in your code what you actually pass to the connected slots.

                    I did, I have one or 2 such case in my current project, it even work with both new and old SIGNAL/SLOT syntax. I believe that changed recently, as I remember it working only with the old one.


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    1
                    • Pradeep KumarP Pradeep Kumar

                      @J.Hilk ,

                      can we use as u mentioned,

                      signals:
                      void signalDefault(QString s = "foo");

                      and emit without argument?.

                      emit signalDefault();

                      Thanks,

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @Pradeep-Kumar yes you can.


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      1
                      • Pradeep KumarP Offline
                        Pradeep KumarP Offline
                        Pradeep Kumar
                        wrote on last edited by
                        #11

                        @jsulm , @J-Hilk ,

                        yes i tried, i am getting the value in slot,

                        so is it the new way, or was present earlier also. just curious.

                        Thanks,

                        Pradeep Kumar
                        Qt,QML Developer

                        jsulmJ 1 Reply Last reply
                        0
                        • Pradeep KumarP Pradeep Kumar

                          @jsulm , @J-Hilk ,

                          yes i tried, i am getting the value in slot,

                          so is it the new way, or was present earlier also. just curious.

                          Thanks,

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Pradeep-Kumar I don't think it's new - it is probably working since C++ allows default values :-)

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          Pradeep KumarP 1 Reply Last reply
                          2
                          • jsulmJ jsulm

                            @Pradeep-Kumar I don't think it's new - it is probably working since C++ allows default values :-)

                            Pradeep KumarP Offline
                            Pradeep KumarP Offline
                            Pradeep Kumar
                            wrote on last edited by
                            #13

                            @jsulm

                            well i tried for the first time, got the output.

                            Thanks,

                            Pradeep Kumar
                            Qt,QML Developer

                            1 Reply Last reply
                            0
                            • VRoninV Offline
                              VRoninV Offline
                              VRonin
                              wrote on last edited by
                              #14

                              You can use the new connect syntax to make this work:
                              connect(act, &QAction::triggered, this, [this]()->void{writeimage(QStringLiteral("currrent"));});

                              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                              ~Napoleon Bonaparte

                              On a crusade to banish setIndexWidget() from the holy land of Qt

                              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