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. [Solved] QSpinBox setMaximum() emits valueChanged() signal, even though value has not changed
QtWS25 Last Chance

[Solved] QSpinBox setMaximum() emits valueChanged() signal, even though value has not changed

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.9k 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.
  • N Offline
    N Offline
    neveralull
    wrote on last edited by
    #1

    Whenever I call setMaximum() in my QSpinBox, I get the valueChanged() signal, even though the value does not change. This causes me to have to put in a kludge, by having a special global flag that I set to ignore the valueChanged() signal before I call setMaximum() and clear the flag afterwards. Either that or I could add a disconnect and connect to the valueChanged() signal. Both solutions are stupid.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi, Which version are you using now?

      I can not reproduce this bug under Windows XP with Qt4.8.0 and Qt5

      @
      #include <QApplication>
      #include <QSpinBox>
      #include <QDebug>

      class Test : public QObject
      {
      Q_OBJECT

      public:
      Test(){}
      public slots:
      void onValueChanged(int i)
      {
      qDebug()<<"Value Changed:"<<i;
      }
      };

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      QSpinBox box;
      box.show();
      Test t;
      a.connect(&box, SIGNAL(valueChanged(int)), &t, SLOT(onValueChanged(int)));
      box.setMaximum(88);
      box.setMinimum(-1);
      box.setValue(2);
      return a.exec();
      }

      #include "main.moc"
      @

      1 Reply Last reply
      0
      • N Offline
        N Offline
        neveralull
        wrote on last edited by
        #3

        I just ran a program similar to yours and could not duplicate the problem either. So I went back to my original code, and determined that there is no problem. What is hapenning is that although I don't change the value, I am setting the maximum lower than the current value. That causes the widget to set the value down to the new maximum, and that causes the valueChanged signal to be emitted.

        I hope you don't mind that I wasted your time with this, but at least I know exactly what's going on now.

        Thanks.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Be sure and edit your original post to add [Solved] to the title. Thanks!

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          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