Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-14259

QSpinBox increments value multiple times on single mouse click when signal handlers are long-running

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3: Somewhat important P3: Somewhat important
    • 5.15.2, 6.0
    • 4.7.0, 5.6.1, 5.9.1
    • None
    • Ubuntu 10.04, 4 GB RAM, Intel Core 2 Duo CPU T7500 @ 2.20 GHz, available disk space: 54 GB.

      When the slots that handle the valueChanged() signal for a QSpinBox are long-running, the QSpinBox will increment the value multiple times, causing not only the value to be incorrect but also recursion as those slots are called repeatedly.

      On my machine (which is about average specs), clicking the "up" arrow on the QSpinBox when running the following program will cause the value to increment from 1 (which is expected) to 4 values per click.

      main.cpp
      #include <QApplication>
      #include <QtGui>
      #include <QtTest>
      
      class MyWindow : public QMainWindow {
        Q_OBJECT
      public:
        explicit MyWindow(QWidget *parent = NULL) : QMainWindow(parent) {
          QSpinBox *spin = new QSpinBox;
          connect(spin, SIGNAL(valueChanged(int)), SLOT(OnSpinBoxChanged()));
          setCentralWidget(spin);
        }
      private slots:
        void OnSpinBoxChanged() {
          qDebug() << "OnSpinBoxChanged()";
          QTest::qSleep(3000);
        }
      };
      
      #include "main.moc"
      
      int main(int argc, char **argv) {
        QApplication app(argc, argv);
        MyWindow win;
        win.show();
        return app.exec();
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            dmateer Dave Mateer
            Votes:
            9 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes