From 2254a1eb3207108555526456d4b35d6110a799c2 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 23 Nov 2015 14:04:54 +0100 Subject: Fix bogus warning when using Binding on value types In addition streamline the code and only do the lookup of the property name once. Change-Id: If2bad4b9179214492ff5692cf1f503f927ca2246 Task-number: QTBUG-48918 Reviewed-by: Simon Hausmann --- src/qml/types/qqmlbind.cpp | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'src/qml/types/qqmlbind.cpp') diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp index bd893bd2f4..45b7edd316 100644 --- a/src/qml/types/qqmlbind.cpp +++ b/src/qml/types/qqmlbind.cpp @@ -50,29 +50,6 @@ QT_BEGIN_NAMESPACE -namespace { - -void validateProperty(QObject *target, const QString &propertyName, QObject *binding) -{ - if (!target) - return; - - const QMetaObject *mo = target->metaObject(); - const int index = mo->indexOfProperty(propertyName.toUtf8()); - if (index == -1) { - qmlInfo(binding) << "Property '" << propertyName << "' does not exist on " << QQmlMetaType::prettyTypeName(target) << "."; - return; - } - - const QMetaProperty mp = mo->property(index); - if (!mp.isWritable()) { - qmlInfo(binding) << "Property '" << propertyName << "' on " << QQmlMetaType::prettyTypeName(target) << " is read-only."; - return; - } -} - -} - class QQmlBindPrivate : public QObjectPrivate { public: @@ -86,8 +63,25 @@ public: QQmlNullableValue value; QQmlProperty prop; QQmlAbstractBinding::Ptr prevBind; + + void validate(QObject *binding) const; }; +void QQmlBindPrivate::validate(QObject *binding) const +{ + if (!obj) + return; + + if (!prop.isValid()) { + qmlInfo(binding) << "Property '" << propName << "' does not exist on " << QQmlMetaType::prettyTypeName(obj) << "."; + return; + } + + if (!prop.isWritable()) { + qmlInfo(binding) << "Property '" << propName << "' on " << QQmlMetaType::prettyTypeName(obj) << " is read-only."; + return; + } +} /*! \qmltype Binding @@ -211,8 +205,8 @@ void QQmlBind::setObject(QObject *obj) } d->obj = obj; if (d->componentComplete) { - validateProperty(d->obj, d->propName, this); d->prop = QQmlProperty(d->obj, d->propName); + d->validate(this); } eval(); } @@ -257,8 +251,8 @@ void QQmlBind::setProperty(const QString &p) } d->propName = p; if (d->componentComplete) { - validateProperty(d->obj, d->propName, this); d->prop = QQmlProperty(d->obj, d->propName); + d->validate(this); } eval(); } @@ -299,8 +293,8 @@ void QQmlBind::componentComplete() Q_D(QQmlBind); d->componentComplete = true; if (!d->prop.isValid()) { - validateProperty(d->obj, d->propName, this); d->prop = QQmlProperty(d->obj, d->propName); + d->validate(this); } eval(); } -- cgit v1.2.3