aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types/qqmlbind.cpp
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig@kdab.com>2015-09-24 10:24:20 +0200
committerTobias Koenig <tobias.koenig@kdab.com>2015-09-24 11:11:54 +0000
commit61ce37de40711ef2d4a6b4989d8183e1711fc47d (patch)
treede0826e4e555047e10fcb41d3871c3edba4649e8 /src/qml/types/qqmlbind.cpp
parentfe7d35e3cbc7b6db42fbc66e26a63d321260cea0 (diff)
Improve warning for QtQml.Binding
Print a warning if there is no property with the given name of the specified target object, or the property is read-only. Change-Id: I5dc2e8330fb1ce53be396b7bf5baf13c1702d2f4 Task-number: QTBUG-39243 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/types/qqmlbind.cpp')
-rw-r--r--src/qml/types/qqmlbind.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp
index a154da8323..df429e5bc1 100644
--- a/src/qml/types/qqmlbind.cpp
+++ b/src/qml/types/qqmlbind.cpp
@@ -36,6 +36,7 @@
#include <private/qqmlnullablevalue_p.h>
#include <private/qqmlproperty_p.h>
#include <private/qqmlbinding_p.h>
+#include <private/qqmlmetatype_p.h>
#include <qqmlengine.h>
#include <qqmlcontext.h>
@@ -49,6 +50,29 @@
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:
@@ -186,8 +210,10 @@ void QQmlBind::setObject(QObject *obj)
d->when = true;
}
d->obj = obj;
- if (d->componentComplete)
+ if (d->componentComplete) {
+ validateProperty(d->obj, d->propName, this);
d->prop = QQmlProperty(d->obj, d->propName);
+ }
eval();
}
@@ -213,8 +239,10 @@ void QQmlBind::setProperty(const QString &p)
d->when = true;
}
d->propName = p;
- if (d->componentComplete)
+ if (d->componentComplete) {
+ validateProperty(d->obj, d->propName, this);
d->prop = QQmlProperty(d->obj, d->propName);
+ }
eval();
}
@@ -253,8 +281,10 @@ void QQmlBind::componentComplete()
{
Q_D(QQmlBind);
d->componentComplete = true;
- if (!d->prop.isValid())
+ if (!d->prop.isValid()) {
+ validateProperty(d->obj, d->propName, this);
d->prop = QQmlProperty(d->obj, d->propName);
+ }
eval();
}