diff options
author | Yulong Bai <yulong.bai@qt.io> | 2017-10-17 14:41:42 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-10-24 16:43:30 +0000 |
commit | 7e7683cabb8df58097c5bc4638a2e08cf6e6ff71 (patch) | |
tree | ec07937eae526476e1cfb6c76b298b7f0e155b7c /tests | |
parent | 7944423bfaec48e5c7642a042bede1557b1beff2 (diff) |
QAction: fix ::setData() always emits changed()
QAction::setData() always emits changed() even without actual data change.
Original code lacks a guard to check if the data changes.
According to http://doc.qt.io/qt-4.8/signalsandslots.html,
adding guard also benefits to prevent infinite looping in case
of cyclic connections.
Task-number: QTBUG-62006
Change-Id: I776369b668082f9f02e4502a36b1ae234ee7e079
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/kernel/qaction/tst_qaction.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp index 83e1850524..3535e465b3 100644 --- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp +++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp @@ -62,6 +62,7 @@ private slots: void task229128TriggeredSignalWithoutActiongroup(); void task229128TriggeredSignalWhenInActiongroup(); void repeat(); + void setData(); private: int m_lastEventType; @@ -408,5 +409,20 @@ void tst_QAction::repeat() QCOMPARE(spy.count(), 2); } +void tst_QAction::setData() // QTBUG-62006 +{ + QAction act(nullptr); + QSignalSpy spy(&act, &QAction::changed); + QCOMPARE(act.data(), QVariant()); + QCOMPARE(spy.count(), 0); + act.setData(QVariant()); + QCOMPARE(spy.count(), 0); + + act.setData(-1); + QCOMPARE(spy.count(), 1); + act.setData(-1); + QCOMPARE(spy.count(), 1); +} + QTEST_MAIN(tst_QAction) #include "tst_qaction.moc" |