summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qdeclarativebinding.cpp4
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/variantsAssignedUndefined.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp20
4 files changed, 35 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp
index 91eb915..e172a8b 100644
--- a/src/declarative/qml/qdeclarativebinding.cpp
+++ b/src/declarative/qml/qdeclarativebinding.cpp
@@ -174,6 +174,10 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags)
data->property.reset();
+ } else if (isUndefined && data->property.propertyType() == qMetaTypeId<QVariant>()) {
+
+ QDeclarativePropertyPrivate::write(data->property, QVariant(), flags);
+
} else if (isUndefined) {
QUrl url = QUrl(data->url);
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
index e89075f..e1e33ab 100644
--- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
@@ -351,6 +351,8 @@ void QDeclarativeObjectScriptClass::setProperty(QObject *obj,
if (value.isUndefined() && lastData->flags & QDeclarativePropertyCache::Data::IsResettable) {
void *a[] = { 0 };
QMetaObject::metacall(obj, QMetaObject::ResetProperty, lastData->coreIndex, a);
+ } else if (value.isUndefined() && lastData->propType == qMetaTypeId<QVariant>()) {
+ QDeclarativePropertyPrivate::write(obj, *lastData, QVariant(), evalContext);
} else if (value.isUndefined()) {
QString error = QLatin1String("Cannot assign [undefined] to ") +
QLatin1String(QMetaType::typeName(lastData->propType));
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/variantsAssignedUndefined.qml b/tests/auto/declarative/qdeclarativeecmascript/data/variantsAssignedUndefined.qml
new file mode 100644
index 0000000..5488e1a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/variantsAssignedUndefined.qml
@@ -0,0 +1,9 @@
+import Qt 4.6
+
+QtObject {
+ property bool runTest: false
+ onRunTestChanged: test1 = undefined
+
+ property variant test1: 10
+ property variant test2: (runTest == false)?11:undefined
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index d886e83..c9fb116 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -140,6 +140,7 @@ private slots:
void nullObjectBinding();
void deletedEngine();
void libraryScriptAssert();
+ void variantsAssignedUndefined();
void callQtInvokables();
private:
@@ -2191,6 +2192,25 @@ void tst_qdeclarativeecmascript::libraryScriptAssert()
delete object;
}
+void tst_qdeclarativeecmascript::variantsAssignedUndefined()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("variantsAssignedUndefined.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test1").toInt(), 10);
+ QCOMPARE(object->property("test2").toInt(), 11);
+
+ object->setProperty("runTest", true);
+
+ QCOMPARE(object->property("test1"), QVariant());
+ QCOMPARE(object->property("test2"), QVariant());
+
+
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"