aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlberto Mardegan <alberto.mardegan@canonical.com>2013-05-29 11:29:52 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-31 22:33:21 +0200
commit843e222b17970c211dfab82215cf41adc4547ab5 (patch)
treedb2343cbf86e6e4361385d52fa71f9a297c41177 /src
parent84627464eb11ca1149d46946b12e3c82eb54a8bf (diff)
QQmlPropertyCache: check methods before properties
When creating the QQmlPropertyData, search within the methods list before searching for properties. The reason is that if the meta object is dynamic, looking up a property will always return a result (if the property doesn't exist, it will be created) and therefore all methods will be obscured. By swapping the search order, we eliminate this risk (methods are not dynamically added). Task-number: QTBUG-29836 Change-Id: Ie367f757c37ef4bc834a6c1c009f27bcf344fe76 Reviewed-by: Matthew Vogt <matthew.vogt@qinetic.com.au> Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index dee9f26c80..4712fbd614 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -1317,6 +1317,31 @@ QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, const QS
Q_ASSERT(metaObject);
QQmlPropertyData rv;
+
+ /* It's important to check the method list before checking for properties;
+ * otherwise, if the meta object is dynamic, a property will be created even
+ * if not found and it might obscure a method having the same name. */
+
+ //Used to block access to QObject::destroyed() and QObject::deleteLater() from QML
+ static const int destroyedIdx1 = QObject::staticMetaObject.indexOfSignal("destroyed(QObject*)");
+ static const int destroyedIdx2 = QObject::staticMetaObject.indexOfSignal("destroyed()");
+ static const int deleteLaterIdx = QObject::staticMetaObject.indexOfSlot("deleteLater()");
+
+ int methodCount = metaObject->methodCount();
+ for (int ii = methodCount - 1; ii >= 0; --ii) {
+ if (ii == destroyedIdx1 || ii == destroyedIdx2 || ii == deleteLaterIdx)
+ continue;
+ QMetaMethod m = metaObject->method(ii);
+ if (m.access() == QMetaMethod::Private)
+ continue;
+ QString methodName = QString::fromUtf8(m.name().constData());
+
+ if (methodName == property) {
+ rv.load(m);
+ return rv;
+ }
+ }
+
{
const QMetaObject *cmo = metaObject;
const QByteArray propertyName = property.toUtf8();
@@ -1342,27 +1367,6 @@ QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, const QS
}
}
}
-
- //Used to block access to QObject::destroyed() and QObject::deleteLater() from QML
- static const int destroyedIdx1 = QObject::staticMetaObject.indexOfSignal("destroyed(QObject*)");
- static const int destroyedIdx2 = QObject::staticMetaObject.indexOfSignal("destroyed()");
- static const int deleteLaterIdx = QObject::staticMetaObject.indexOfSlot("deleteLater()");
-
- int methodCount = metaObject->methodCount();
- for (int ii = methodCount - 1; ii >= 0; --ii) {
- if (ii == destroyedIdx1 || ii == destroyedIdx2 || ii == deleteLaterIdx)
- continue;
- QMetaMethod m = metaObject->method(ii);
- if (m.access() == QMetaMethod::Private)
- continue;
- QString methodName = QString::fromUtf8(m.name().constData());
-
- if (methodName == property) {
- rv.load(m);
- return rv;
- }
- }
-
return rv;
}