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. Getting two signals inside one slot
QtWS25 Last Chance

Getting two signals inside one slot

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 433 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.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by viniltc
    #1

    Hi All,

    I'm a bit confused getting two signals inside one slot

    void Program::nextBtn()
    {
        m_currentBtn++;
        if(m_currentBtn > btnGrp->buttons().size())
        {
            m_currentBtn = 0;
        }
    
        emit buttonChanged(m_currentBtn);  // signal 1
    }
    
    void Program::changeValue(int value)
    {
    
        CurPoint1->setY(value);
        CurPoint2->setY(value);
        update();
    
        emit pulseWidthValue(adjust_PW_range(CurPoint1->y())); // signal 2
    
    }
    

    At present , I do connect:

    connect(ui->btn_nextPhase, &QPushButton::clicked, this, &Program::nextBtn);
    connect(this, &Program::buttonChanged, this, &Program::paintBtn);
    

    to get value of buttonChanged signal inside paintBtn slot.

    But now I need value from pulseWidthValue signal as well inside paintBtn slot..

    How do I modify the paintBtn definition to get both the signal values?

    Or is there better workaround to this problem?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You can simply add the extra parameter to the signal and slot definitions
      and emit it with the new value
      emit buttonChanged(m_currentBtn, adjust_PW_range(CurPoint1->y()) );
      make sure also change paintBtn so it has this extra paramter.

      1 Reply Last reply
      3
      • V Offline
        V Offline
        viniltc
        wrote on last edited by viniltc
        #3

        @mrjj Hi, thanks a lot for your feedback.

        I could not find what's the issue with the following scenario that not works:

        Not Working - Run time error: One signal implimentation

        void nextBtn();
        void paintBtn(int id, int pwvalue);
        
        signals:
                void buttonChanged(int id, int pwvalue);
        
        // connections
         connect(ui->btn_nextPhase, &QPushButton::clicked, this, &Program::nextBtn);
         connect(this, &Program::buttonChanged, this, &Program::paintBtn);
        
        void Program::nextBtn()
        {
            m_currentBtn++;
            if(m_currentBtn > btnGrp->buttons().size())
            {
                m_currentBtn = 0;
            }
        
            emit buttonChanged(m_currentBtn, adjust_PW_range(CurPoint1->y()));
        }
        
        
        void Program::paintBtn(int id, int pwvalue)
        {
            ui->label_7->setText(QString::number(pwvalue));
        }
        

        Working scenario: Two signals

        void changeValue(int value );
        void nextBtn(int pwvalue);
        void paintBtn(int id, int pwvalue);
        
        signals:
                void buttonChanged(int id, int pwvalue);
                void pulseWidthValue(int pwvalue);
        
        
         connect(ui->btn_nextPhase, &QPushButton::clicked, this, &ProgramPalmerGrasp::nextBtn);
        
            connect(this, &Program::buttonChanged, this, &Program::paintBtn);
            connect(this, &Program::pulseWidthValue, this, &Program::nextBtn);
        
        
        void Program::changeValue(int value)
        {
        
            CurPoint1->setY(value);
            CurPoint2->setY(value);
            update();
        
            emit pulseWidthValue(adjust_PW_range(CurPoint1->y())); 
        
        }
        
        
        void Program::nextBtn(int pwvalue)
        {
            m_currentBtn++;
            if(m_currentBtn > btnGrp->buttons().size())
            {
                m_currentBtn = 0;
            }
        
             emit buttonChanged(m_currentBtn, pwvalue);
        }
        
        void Program::paintBtn(int id, int pwvalue)
        {
            ui->label_7->setText(QString::number(pwvalue));
        }
        
        
        JonBJ 1 Reply Last reply
        0
        • V viniltc

          @mrjj Hi, thanks a lot for your feedback.

          I could not find what's the issue with the following scenario that not works:

          Not Working - Run time error: One signal implimentation

          void nextBtn();
          void paintBtn(int id, int pwvalue);
          
          signals:
                  void buttonChanged(int id, int pwvalue);
          
          // connections
           connect(ui->btn_nextPhase, &QPushButton::clicked, this, &Program::nextBtn);
           connect(this, &Program::buttonChanged, this, &Program::paintBtn);
          
          void Program::nextBtn()
          {
              m_currentBtn++;
              if(m_currentBtn > btnGrp->buttons().size())
              {
                  m_currentBtn = 0;
              }
          
              emit buttonChanged(m_currentBtn, adjust_PW_range(CurPoint1->y()));
          }
          
          
          void Program::paintBtn(int id, int pwvalue)
          {
              ui->label_7->setText(QString::number(pwvalue));
          }
          

          Working scenario: Two signals

          void changeValue(int value );
          void nextBtn(int pwvalue);
          void paintBtn(int id, int pwvalue);
          
          signals:
                  void buttonChanged(int id, int pwvalue);
                  void pulseWidthValue(int pwvalue);
          
          
           connect(ui->btn_nextPhase, &QPushButton::clicked, this, &ProgramPalmerGrasp::nextBtn);
          
              connect(this, &Program::buttonChanged, this, &Program::paintBtn);
              connect(this, &Program::pulseWidthValue, this, &Program::nextBtn);
          
          
          void Program::changeValue(int value)
          {
          
              CurPoint1->setY(value);
              CurPoint2->setY(value);
              update();
          
              emit pulseWidthValue(adjust_PW_range(CurPoint1->y())); 
          
          }
          
          
          void Program::nextBtn(int pwvalue)
          {
              m_currentBtn++;
              if(m_currentBtn > btnGrp->buttons().size())
              {
                  m_currentBtn = 0;
              }
          
               emit buttonChanged(m_currentBtn, pwvalue);
          }
          
          void Program::paintBtn(int id, int pwvalue)
          {
              ui->label_7->setText(QString::number(pwvalue));
          }
          
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @viniltc said in Getting two signals inside one slot:

          Not Working - Run time error: One signal implimentation

          What run time error message?

          1 Reply Last reply
          1
          • V Offline
            V Offline
            viniltc
            wrote on last edited by
            #5

            @JonB , It just stops the application. Even the debug terminal crashes, I cant spot where exactly is the issue ..

            1 Reply Last reply
            0
            • V Offline
              V Offline
              viniltc
              wrote on last edited by
              #6

              The debug took long time to point at:

              emit buttonChanged(m_currentBtn, adjust_PW_range(CurPoint1->y()));
              

              Throws the following message:

              ed3e64f1-1089-417a-89c6-bb075aa296cd-image.png

              JonBJ 1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                Hi
                I would guess on that
                emit buttonChanged(m_currentBtn, adjust_PW_range(CurPoint1->y()));

                When you call this, you have not yet ALLOCATED CurPoint1

                so it crashes.

                Make sure its valid at this point in time.

                1 Reply Last reply
                4
                • V viniltc

                  The debug took long time to point at:

                  emit buttonChanged(m_currentBtn, adjust_PW_range(CurPoint1->y()));
                  

                  Throws the following message:

                  ed3e64f1-1089-417a-89c6-bb075aa296cd-image.png

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @viniltc
                  And further to @mrjj, if you run your app from within the debugger it should break on that exception, and give you a stack trace showing you are executing expressionCurPoint1->y().

                  1 Reply Last reply
                  2

                  • Login

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