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
Forum Updated to NodeBB v4.3 + New Features

Query signal for value in lambda function

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.6k 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 23 Oct 2017, 16:42 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?

    K 1 Reply Last reply 23 Oct 2017, 19:08
    0
    • S Sewing
      23 Oct 2017, 16:42

      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?

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 23 Oct 2017, 19:08 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 23 Oct 2017, 19:20 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 24 Oct 2017, 05:28 last edited by
          #4

          thank you!

          @kshegunov
          void ImgSeqCtrlWidget::step(int);

          J 1 Reply Last reply 24 Oct 2017, 05:43
          0
          • S Sewing
            24 Oct 2017, 05:28

            thank you!

            @kshegunov
            void ImgSeqCtrlWidget::step(int);

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 24 Oct 2017, 05:43 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 24 Oct 2017, 06:13 last edited by
              #6

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

              J 1 Reply Last reply 24 Oct 2017, 06:25
              0
              • S Sewing
                24 Oct 2017, 06:13

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

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 24 Oct 2017, 06:25 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 24 Oct 2017, 07:45 last edited by
                  #8

                  thank you!

                  1 Reply Last reply
                  0

                  1/8

                  23 Oct 2017, 16:42

                  • Login

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