From 1c1cce67fa1d03a49cdfb6f1ca378b182925ffdb Mon Sep 17 00:00:00 2001 From: Pavel Krebs Date: Fri, 5 Dec 2014 15:39:48 +0100 Subject: QScrollBar: emit valueChanged once even if a slot takes too much time Put also processing of control activation into initial timer check for possibly pending mouse release event. [ChangeLog][QtWidgets][QScrollBar] Fixed a bug where the valueChanged() signal was emitted twice if a connected slot took too much time. Task-number: QTBUG-42871 Change-Id: I7bad5279ef84463a033b55256d241d4445374081 Reviewed-by: Giuseppe D'Angelo --- .../widgets/widgets/qscrollbar/tst_qscrollbar.cpp | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp index cb0383c398..008d3b2435 100644 --- a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp +++ b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp @@ -58,6 +58,7 @@ private slots: #ifndef QT_NO_WHEELEVENT void QTBUG_27308(); #endif + void QTBUG_42871(); }; class SingleStepTestScrollBar : public QScrollBar { @@ -169,5 +170,44 @@ void tst_QScrollBar::QTBUG_27308() } #endif +class QTBUG_42871_Handler : public QObject { + Q_OBJECT +public: + int updatesCount; + QTBUG_42871_Handler() : QObject(), updatesCount(0) {} +public slots: + void valueUpdated(int) { ++updatesCount; QTest::qSleep(600); } +}; + +void tst_QScrollBar::QTBUG_42871() +{ + QTBUG_42871_Handler myHandler; + QScrollBar scrollBarWidget(Qt::Vertical); + bool connection = connect(&scrollBarWidget, SIGNAL(valueChanged(int)), &myHandler, SLOT(valueUpdated(int))); + QVERIFY(connection); + scrollBarWidget.resize(100, scrollBarWidget.height()); + centerOnScreen(&scrollBarWidget); + scrollBarWidget.show(); + QTest::qWaitForWindowExposed(&scrollBarWidget); + QSignalSpy spy(&scrollBarWidget, SIGNAL(actionTriggered(int))); + QVERIFY(spy.isValid()); + QCOMPARE(myHandler.updatesCount, 0); + QCOMPARE(spy.count(), 0); + + // Simulate a mouse click on the "scroll down button". + const QPoint pressPoint(scrollBarWidget.width() / 2, scrollBarWidget.height() - 10); + const QPoint globalPressPoint = scrollBarWidget.mapToGlobal(pressPoint); + QMouseEvent mousePressEvent(QEvent::MouseButtonPress, pressPoint, globalPressPoint, + Qt::LeftButton, Qt::LeftButton, 0); + QApplication::sendEvent(&scrollBarWidget, &mousePressEvent); + QTest::qWait(1); + QMouseEvent mouseReleaseEvent(QEvent::MouseButtonRelease, pressPoint, globalPressPoint, + Qt::LeftButton, Qt::LeftButton, 0); + QApplication::sendEvent(&scrollBarWidget, &mouseReleaseEvent); + // Check that the action was triggered once. + QCOMPARE(myHandler.updatesCount, 1); + QCOMPARE(spy.count(), 1); +} + QTEST_MAIN(tst_QScrollBar) #include "tst_qscrollbar.moc" -- cgit v1.2.3