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>
This commit is contained in:
parent
7944423bfa
commit
7e7683cabb
@ -1118,6 +1118,8 @@ void
|
||||
QAction::setData(const QVariant &data)
|
||||
{
|
||||
Q_D(QAction);
|
||||
if (d->userData == data)
|
||||
return;
|
||||
d->userData = data;
|
||||
d->sendDataChanged();
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user