summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPavel Krebs <pkrebs@amberg.cz>2014-12-05 15:39:48 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2014-12-19 17:15:07 +0100
commit1c1cce67fa1d03a49cdfb6f1ca378b182925ffdb (patch)
tree9957997cf2e4beb1648ba6d46c47c738aa6204ed /tests
parentb6514cf30761b01b477edef67217a48a59268886 (diff)
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 <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp40
1 files changed, 40 insertions, 0 deletions
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"