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. QSlider valueChanged connection not working
Forum Updated to NodeBB v4.3 + New Features

QSlider valueChanged connection not working

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 1.3k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I have written a widget which I use in two places:
    0ee06d63-d88b-4d60-9101-2d195ddab7b2-image.png
    At the right of the display there are three controls, two spinners and a pushbutton. The spinners are used to set common attributes for the widgets, the maximum and minimum values to show.

    In the class I have defined static pointers so that each graphic can access the values of the controls, in the constructor I have code like:

            truth::mspSpinMax = new QSpinBox(pParent);
            truth::mspSpinMax->setSingleStep(truth::mscuint16StepSize - 1);
            truth::mspSpinMax->setMaximum(truth::msintMaximum);
            truth::mspSpinMax->setValue(truth::msintMaximum);
            truth::mscnSpinMaxValueChanged =
                QObject::connect(truth::mspSpinMax,
                    QOverload<int>::of(&QSpinBox::valueChanged),
                [this](int intValue)
                {
                    if ( truth::mspBtnUpdate != nullptr )
                    {
                        truth::mspBtnUpdate->setEnabled(truth::msintLastMax != intValue);
                    }
                }
            );
    

    The problem is that the signals are not making it to the slots, in that the lambda slots I am using never get called. What could be wrong?

    Kind Regards,
    Sy

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • SPlattenS SPlatten

      @J-Hilk , @jsulm , something very strange is happening, I thought I would try adding another connection:

      truth::mscnSpinMaxValueChanged =
                  QObject::connect(truth::mspSpinMax,
                      QOverload<int>::of(&QSpinBox::valueChanged),
                  [this](int intValue)
                  {
                      if ( truth::mspBtnUpdate != nullptr )
                      {
                          truth::mspBtnUpdate->setEnabled(truth::msintLastMax != intValue);
                      }
                  }
              );
      truth::mscnSpinMaxValueChanged =
                  QObject::connect(truth::mspSpinMax,
                      QOverload<int>::of(&QSpinBox::valueChanged),
                  [this](int intValue)
                  {
      qDebug() << intValue;
                  }
              );
      

      Now the first connection is working and the debugger stops in the slot...the second connection doesn't work and no debug output appears.

      It has to be a bug because with both connections the first connection works, if I comment out the second it doesn't work.

      Qt Creator 4.4.1
      Based on Qt 5.9.2 (MSVC 2015, 32 bit)

      Unfortunately I cannot upgrade Qt or MSVC, these are the versions I have to work with. Could it be something to do with the static member references in the first slot?

      SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #10

      @SPlatten , What I found that works:

      QObject::connect(truth::mspSpinMax,
                      QOverload<int>::of(&QSpinBox::valueChanged),
                  [this](int intValue)
                  {
                     emit maximumChanged(intValue);
                  }
              );
      

      Kind Regards,
      Sy

      1 Reply Last reply
      0
      • SPlattenS SPlatten

        I have written a widget which I use in two places:
        0ee06d63-d88b-4d60-9101-2d195ddab7b2-image.png
        At the right of the display there are three controls, two spinners and a pushbutton. The spinners are used to set common attributes for the widgets, the maximum and minimum values to show.

        In the class I have defined static pointers so that each graphic can access the values of the controls, in the constructor I have code like:

                truth::mspSpinMax = new QSpinBox(pParent);
                truth::mspSpinMax->setSingleStep(truth::mscuint16StepSize - 1);
                truth::mspSpinMax->setMaximum(truth::msintMaximum);
                truth::mspSpinMax->setValue(truth::msintMaximum);
                truth::mscnSpinMaxValueChanged =
                    QObject::connect(truth::mspSpinMax,
                        QOverload<int>::of(&QSpinBox::valueChanged),
                    [this](int intValue)
                    {
                        if ( truth::mspBtnUpdate != nullptr )
                        {
                            truth::mspBtnUpdate->setEnabled(truth::msintLastMax != intValue);
                        }
                    }
                );
        

        The problem is that the signals are not making it to the slots, in that the lambda slots I am using never get called. What could be wrong?

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

        @SPlatten said in QSlider valueChanged connection not working:

        in that the lambda slots I am using never get called

        How did you prove that?

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

        SPlattenS N 2 Replies Last reply
        0
        • SPlattenS SPlatten

          I have written a widget which I use in two places:
          0ee06d63-d88b-4d60-9101-2d195ddab7b2-image.png
          At the right of the display there are three controls, two spinners and a pushbutton. The spinners are used to set common attributes for the widgets, the maximum and minimum values to show.

          In the class I have defined static pointers so that each graphic can access the values of the controls, in the constructor I have code like:

                  truth::mspSpinMax = new QSpinBox(pParent);
                  truth::mspSpinMax->setSingleStep(truth::mscuint16StepSize - 1);
                  truth::mspSpinMax->setMaximum(truth::msintMaximum);
                  truth::mspSpinMax->setValue(truth::msintMaximum);
                  truth::mscnSpinMaxValueChanged =
                      QObject::connect(truth::mspSpinMax,
                          QOverload<int>::of(&QSpinBox::valueChanged),
                      [this](int intValue)
                      {
                          if ( truth::mspBtnUpdate != nullptr )
                          {
                              truth::mspBtnUpdate->setEnabled(truth::msintLastMax != intValue);
                          }
                      }
                  );
          

          The problem is that the signals are not making it to the slots, in that the lambda slots I am using never get called. What could be wrong?

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

          @SPlatten

          are you mixing something up here ?

          truth::mscnSpinMaxValueChanged =
                      QObject::connect(truth::mspSpinMax,
                          QOverload<int>::of(&QSpinBox::valueChanged),
                      [this](int intValue)
                      {
                          if ( truth::mspBtnUpdate != nullptr )
                          {
                              truth::mspBtnUpdate->setEnabled(truth::msintLastMax != intValue);
                          }
                      }
                  );
          

          the return type of QObject::connect is a QMetaObject::Connection that allows for a implicit conversion to bool and therefore int.

          You seem to want to assign it to a int value mscnSpinMaxValueChanged ?


          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.

          SPlattenS 1 Reply Last reply
          1
          • jsulmJ jsulm

            @SPlatten said in QSlider valueChanged connection not working:

            in that the lambda slots I am using never get called

            How did you prove that?

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #4

            @jsulm , Whilst debugging in Qt Creator with breakpoint in slot.

            Kind Regards,
            Sy

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

              @SPlatten

              are you mixing something up here ?

              truth::mscnSpinMaxValueChanged =
                          QObject::connect(truth::mspSpinMax,
                              QOverload<int>::of(&QSpinBox::valueChanged),
                          [this](int intValue)
                          {
                              if ( truth::mspBtnUpdate != nullptr )
                              {
                                  truth::mspBtnUpdate->setEnabled(truth::msintLastMax != intValue);
                              }
                          }
                      );
              

              the return type of QObject::connect is a QMetaObject::Connection that allows for a implicit conversion to bool and therefore int.

              You seem to want to assign it to a int value mscnSpinMaxValueChanged ?

              SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #5

              @J-Hilk , mscnSpinMaxValueChanged is defined in the class as:

              static QMetaObject::Connection mscnSpinMaxValueChanged;
              

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • jsulmJ jsulm

                @SPlatten said in QSlider valueChanged connection not working:

                in that the lambda slots I am using never get called

                How did you prove that?

                N Offline
                N Offline
                Nan Feng
                wrote on last edited by
                #6
                This post is deleted!
                SPlattenS jsulmJ 2 Replies Last reply
                0
                • N Nan Feng

                  This post is deleted!

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #7

                  @Nan-Feng , what has this got to do with the subject????

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0
                  • N Nan Feng

                    This post is deleted!

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

                    @Nan-Feng Please post your questions in your own threads!

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

                    1 Reply Last reply
                    0
                    • SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by SPlatten
                      #9

                      @J-Hilk , @jsulm , something very strange is happening, I thought I would try adding another connection:

                      truth::mscnSpinMaxValueChanged =
                                  QObject::connect(truth::mspSpinMax,
                                      QOverload<int>::of(&QSpinBox::valueChanged),
                                  [this](int intValue)
                                  {
                                      if ( truth::mspBtnUpdate != nullptr )
                                      {
                                          truth::mspBtnUpdate->setEnabled(truth::msintLastMax != intValue);
                                      }
                                  }
                              );
                      truth::mscnSpinMaxValueChanged =
                                  QObject::connect(truth::mspSpinMax,
                                      QOverload<int>::of(&QSpinBox::valueChanged),
                                  [this](int intValue)
                                  {
                      qDebug() << intValue;
                                  }
                              );
                      

                      Now the first connection is working and the debugger stops in the slot...the second connection doesn't work and no debug output appears.

                      It has to be a bug because with both connections the first connection works, if I comment out the second it doesn't work.

                      Qt Creator 4.4.1
                      Based on Qt 5.9.2 (MSVC 2015, 32 bit)

                      Unfortunately I cannot upgrade Qt or MSVC, these are the versions I have to work with. Could it be something to do with the static member references in the first slot?

                      Kind Regards,
                      Sy

                      SPlattenS 1 Reply Last reply
                      0
                      • SPlattenS SPlatten

                        @J-Hilk , @jsulm , something very strange is happening, I thought I would try adding another connection:

                        truth::mscnSpinMaxValueChanged =
                                    QObject::connect(truth::mspSpinMax,
                                        QOverload<int>::of(&QSpinBox::valueChanged),
                                    [this](int intValue)
                                    {
                                        if ( truth::mspBtnUpdate != nullptr )
                                        {
                                            truth::mspBtnUpdate->setEnabled(truth::msintLastMax != intValue);
                                        }
                                    }
                                );
                        truth::mscnSpinMaxValueChanged =
                                    QObject::connect(truth::mspSpinMax,
                                        QOverload<int>::of(&QSpinBox::valueChanged),
                                    [this](int intValue)
                                    {
                        qDebug() << intValue;
                                    }
                                );
                        

                        Now the first connection is working and the debugger stops in the slot...the second connection doesn't work and no debug output appears.

                        It has to be a bug because with both connections the first connection works, if I comment out the second it doesn't work.

                        Qt Creator 4.4.1
                        Based on Qt 5.9.2 (MSVC 2015, 32 bit)

                        Unfortunately I cannot upgrade Qt or MSVC, these are the versions I have to work with. Could it be something to do with the static member references in the first slot?

                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by
                        #10

                        @SPlatten , What I found that works:

                        QObject::connect(truth::mspSpinMax,
                                        QOverload<int>::of(&QSpinBox::valueChanged),
                                    [this](int intValue)
                                    {
                                       emit maximumChanged(intValue);
                                    }
                                );
                        

                        Kind Regards,
                        Sy

                        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