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. Query signal for value in lambda function

Query signal for value in lambda function

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.8k 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.
  • S Offline
    S Offline
    Sewing
    wrote on last edited by
    #1

    I am trying to use the following syntax to propagate a signal up my widget hierarchy

      connect(imgSeqCtrl, &ImgSeqCtrlWidget::step,  [this]() {  emit mySignal(1);  });
    
    

    where step is a signal with the following signature

    void step(int);

    Now, I want to emit a different signal depending on the sign of the step's signal value. Is there a possibility to query the steps actual value inside the lambda or is there now way around an additional dispatch function in which I do the case query?

    kshegunovK 1 Reply Last reply
    0
    • S Sewing

      I am trying to use the following syntax to propagate a signal up my widget hierarchy

        connect(imgSeqCtrl, &ImgSeqCtrlWidget::step,  [this]() {  emit mySignal(1);  });
      
      

      where step is a signal with the following signature

      void step(int);

      Now, I want to emit a different signal depending on the sign of the step's signal value. Is there a possibility to query the steps actual value inside the lambda or is there now way around an additional dispatch function in which I do the case query?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      What is the signature of ImgSeqCtrlWidget::step?

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      3
      • T Offline
        T Offline
        t3685
        wrote on last edited by t3685
        #3

        Yes, you need to change your lambda to:

        [this](int value) { 
        if (value < 0) 
            emit signal1(); 
        else 
            emit signal2();
        }
        

        Basically the lambda needs to take the same (or less) arguments as your initial signal.

        1 Reply Last reply
        5
        • S Offline
          S Offline
          Sewing
          wrote on last edited by
          #4

          thank you!

          @kshegunov
          void ImgSeqCtrlWidget::step(int);

          J.HilkJ 1 Reply Last reply
          0
          • S Sewing

            thank you!

            @kshegunov
            void ImgSeqCtrlWidget::step(int);

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

            @Sewing Just to complete the picture, you don't need a Lambda to propagate a Sigal, you can connect Signals to Signals as long as the arguments are compatible, which theay are in your case:

            connect(imgSeqCtrl, &ImgSeqCtrlWidget::step,  this, &myClassName::mySignal);
            

            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
            3
            • S Offline
              S Offline
              Sewing
              wrote on last edited by
              #6

              Yes, but what if I want to send my signal, equipped with two different values?

              J.HilkJ 1 Reply Last reply
              0
              • S Sewing

                Yes, but what if I want to send my signal, equipped with two different values?

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

                @Sewing well that depends, if you want to add a new argument to your Signal than you'll need a function to do that, that function can be an actual SLOT of your class or a lambda.

                however droping arguments, no problem

                //SignalA(int index, QString text);
                //SignalB(int index);
                
                //This os ok
                connect(objectA, &&QObject::SignalA, objectB, &QObject::SignalB);
                
                //This is not
                connect(objectB, &&QObject::SignalB, objectA, &QObject::SignalA);
                
                //Howver iirc this should work:
                //SignalA(int index, QString text = "DefaultText");
                //SignalB(int index);
                connect(objectB, SIGNAL(SignalB(int)), objectA, SIGNAL(SignalA(int,QString)));
                

                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
                2
                • S Offline
                  S Offline
                  Sewing
                  wrote on last edited by
                  #8

                  thank you!

                  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