Details
-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
None
-
5.4.2, 5.5.1
-
None
Description
QMetaProperty::write or QObject::setProperty writes null string instead of empty string (does nothing) to property when the initial value of the property is null string.
I noticed it filling object properties through Q_PROPERTY with MEMBER attribute (works well with WRITE accessor and the assignment operator in the setter).
Example
X a, b; a.setProperty("value", ""); b.setProperty("value", "abc"); b.setProperty("value", ""); qDebug() << a.property("value").isNull() << b.property("value").isNull();
class X : public QObject { ... Q_PROPERTY(QString value MEMBER _value) ... } Output: true false
class X : public QObject { ... Q_PROPERTY(QString value READ value WRITE setValue) ... void setValue(const QString &value) { _value = value; } ... } Output: false false
There is no problem with the dynamic properties.
QObject o; o.setProperty("dynamic", ""); // o.property("dynamic").isNull() = false o.setProperty("dynamic", "abc"); // o.property("dynamic").isNull() = false o.setProperty("dynamic", QString()); // o.property("dynamic").isNull() = true