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



  • 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.



  • 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"
    @



  • 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.


  • Moderators

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.