diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2018-08-03 17:55:11 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2018-08-04 15:46:02 +0000 |
commit | 64a560d977a0a511ef541d6116d82e7b5c911a92 (patch) | |
tree | 704115319f973cddc0683178cd9b66ce7d76cd2c /tests/auto/corelib/kernel/qobject/tst_qobject.cpp | |
parent | 4c223502787f604fc8e726b0f9006c868810c08d (diff) |
QObject: do allow setProperty() to change the type of the property
[ChangeLog][QtCore][QObject] Fixed a bug in setProperty() that caused a
property change not to take effect if the old value compared equal using
QVariant's equality operator, but the values were not strictly equal.
Task-number: QTBUG-69744
Change-Id: I00e04a465fcf4fc1a462fffd1547885861a07a64
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp')
-rw-r--r-- | tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index c734cfe4dd..ec57522f48 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -2976,6 +2976,7 @@ void tst_QObject::dynamicProperties() QVERIFY(obj.dynamicPropertyNames().isEmpty()); + // set a non-dynamic property QVERIFY(obj.setProperty("number", 42)); QVERIFY(obj.changedDynamicProperties.isEmpty()); QCOMPARE(obj.property("number").toInt(), 42); @@ -2983,19 +2984,30 @@ void tst_QObject::dynamicProperties() QVERIFY(!obj.setProperty("number", "invalid string")); QVERIFY(obj.changedDynamicProperties.isEmpty()); + // set a dynamic property QVERIFY(!obj.setProperty("myuserproperty", "Hello")); QCOMPARE(obj.changedDynamicProperties.count(), 1); QCOMPARE(obj.changedDynamicProperties.first(), QByteArray("myuserproperty")); //check if there is no redundant DynamicPropertyChange events QVERIFY(!obj.setProperty("myuserproperty", "Hello")); QCOMPARE(obj.changedDynamicProperties.count(), 1); - obj.changedDynamicProperties.clear(); + QCOMPARE(obj.property("myuserproperty").type(), QVariant::String); QCOMPARE(obj.property("myuserproperty").toString(), QString("Hello")); QCOMPARE(obj.dynamicPropertyNames().count(), 1); QCOMPARE(obj.dynamicPropertyNames().first(), QByteArray("myuserproperty")); + // change type of the dynamic property + obj.changedDynamicProperties.clear(); + QVERIFY(!obj.setProperty("myuserproperty", QByteArray("Hello"))); + QCOMPARE(obj.changedDynamicProperties.count(), 1); + QCOMPARE(obj.changedDynamicProperties.first(), QByteArray("myuserproperty")); + QCOMPARE(obj.property("myuserproperty").type(), QVariant::ByteArray); + QCOMPARE(obj.property("myuserproperty").toString(), QByteArray("Hello")); + + // unset the property + obj.changedDynamicProperties.clear(); QVERIFY(!obj.setProperty("myuserproperty", QVariant())); QCOMPARE(obj.changedDynamicProperties.count(), 1); |