aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/compiler/qv4compileddata_p.h2
-rw-r--r--src/qml/qml/qqmlproperty.cpp6
-rw-r--r--tests/auto/qml/qqmllanguage/data/assignNullStrings.qml9
-rw-r--r--tests/auto/qml/qqmllanguage/testtypes.h11
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp14
5 files changed, 42 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index afcf2c6a24..a4dcfd9209 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -196,6 +196,8 @@ struct Unit
const uint *offsetTable = reinterpret_cast<const uint*>((reinterpret_cast<const char *>(this)) + offsetToStringTable);
const uint offset = offsetTable[idx];
const String *str = reinterpret_cast<const String*>(reinterpret_cast<const char *>(this) + offset);
+ if (str->str.size == 0)
+ return QString();
QStringDataPtr holder = { const_cast<QStringData *>(static_cast<const QStringData*>(&str->str)) };
QString qstr(holder);
if (flags & StaticData)
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 0bbcafda54..1075b53c5e 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1403,6 +1403,12 @@ bool QQmlPropertyPrivate::write(QObject *object,
v = value;
if (v.convert(propertyType)) {
ok = true;
+ } else if (v.isValid() && value.isNull()) {
+ // For historical reasons converting a null QVariant to another type will do the trick
+ // but return false anyway. This is caught with the above condition and considered a
+ // successful conversion.
+ Q_ASSERT(v.userType() == propertyType);
+ ok = true;
} else if ((uint)propertyType >= QVariant::UserType && variantType == QVariant::String) {
QQmlMetaType::StringConverter con = QQmlMetaType::customStringConverter(propertyType);
if (con) {
diff --git a/tests/auto/qml/qqmllanguage/data/assignNullStrings.qml b/tests/auto/qml/qqmllanguage/data/assignNullStrings.qml
new file mode 100644
index 0000000000..5e1c3a9b03
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/assignNullStrings.qml
@@ -0,0 +1,9 @@
+import Test 1.0
+MyTypeObject {
+ stringProperty: ""
+ byteArrayProperty: ""
+ function assignNullStringsFromJs() {
+ stringProperty = ""
+ byteArrayProperty = ""
+ }
+}
diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h
index 6a6b2eba45..1c13a2e21c 100644
--- a/tests/auto/qml/qqmllanguage/testtypes.h
+++ b/tests/auto/qml/qqmllanguage/testtypes.h
@@ -236,6 +236,7 @@ class MyTypeObject : public QObject
Q_PROPERTY(MyMirroredEnum mirroredEnumProperty READ mirroredEnumProperty WRITE setMirroredEnumProperty NOTIFY mirroredEnumPropertyChanged)
Q_PROPERTY(MyEnumContainer::RelatedEnum relatedEnumProperty READ relatedEnumProperty WRITE setRelatedEnumProperty)
Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringPropertyChanged)
+ Q_PROPERTY(QByteArray byteArrayProperty READ byteArrayProperty WRITE setByteArrayProperty NOTIFY byteArrayPropertyChanged)
Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty NOTIFY uintPropertyChanged)
Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged)
Q_PROPERTY(qreal realProperty READ realProperty WRITE setRealProperty NOTIFY realPropertyChanged)
@@ -357,6 +358,15 @@ public:
emit stringPropertyChanged();
}
+ QByteArray byteArrayPropertyValue;
+ QByteArray byteArrayProperty() const {
+ return byteArrayPropertyValue;
+ }
+ void setByteArrayProperty(const QByteArray &v) {
+ byteArrayPropertyValue = v;
+ emit byteArrayPropertyChanged();
+ }
+
uint uintPropertyValue;
uint uintProperty() const {
return uintPropertyValue;
@@ -570,6 +580,7 @@ signals:
void qtEnumPropertyChanged();
void mirroredEnumPropertyChanged();
void stringPropertyChanged();
+ void byteArrayPropertyChanged();
void uintPropertyChanged();
void intPropertyChanged();
void realPropertyChanged();
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 55d07e78da..87f811cbbc 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -110,6 +110,7 @@ private slots:
void assignLiteralToVariant();
void assignLiteralToVar();
void assignLiteralToJSValue();
+ void assignNullStrings();
void bindJSValueToVar();
void bindJSValueToVariant();
void bindJSValueToType();
@@ -873,6 +874,19 @@ void tst_qqmllanguage::assignLiteralToJSValue()
}
}
+void tst_qqmllanguage::assignNullStrings()
+{
+ QQmlComponent component(&engine, testFileUrl("assignNullStrings.qml"));
+ VERIFY_ERRORS(0);
+ MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
+ QVERIFY(object != 0);
+ QVERIFY(object->stringProperty().isNull());
+ QVERIFY(object->byteArrayProperty().isNull());
+ QMetaObject::invokeMethod(object, "assignNullStringsFromJs", Qt::DirectConnection);
+ QVERIFY(object->stringProperty().isNull());
+ QVERIFY(object->byteArrayProperty().isNull());
+}
+
void tst_qqmllanguage::bindJSValueToVar()
{
QQmlComponent component(&engine, testFileUrl("assignLiteralToJSValue.qml"));