aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-11-23 14:04:54 +0100
committerLars Knoll <lars.knoll@theqtcompany.com>2015-11-27 11:36:52 +0000
commit2254a1eb3207108555526456d4b35d6110a799c2 (patch)
tree6294e1f4d673d892ba336832fd41ee9302142c04 /src
parentf0670e5b5da985804f1b50a8f69d6612b150ee87 (diff)
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 <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/types/qqmlbind.cpp46
1 files changed, 20 insertions, 26 deletions
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<QVariant> 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();
}