Remove hardcoded assumptions about methods in QObject
authorChris Adams <christopher.adams@nokia.com>
Tue, 20 Dec 2011 05:33:47 +0000 (15:33 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 20 Dec 2011 06:34:58 +0000 (07:34 +0100)
This commit ensures that the number of methods available from the
QObject::staticMetaObject is looked up rather than hardcoded to
a value in the QDeclarativePropertyCache.

Task-number: QTBUG-22985
Change-Id: If61c02f0d32066cddaeac2d8143c58db97acb609
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
src/declarative/qml/qdeclarativepropertycache.cpp

index 67d0cea..bd3bc33 100644 (file)
@@ -357,8 +357,9 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb
         }
     }
 
-    // 3 to block the destroyed signal and the deleteLater() slot
-    int methodOffset = qMax(3, metaObject->methodOffset()); 
+    // qMax(defaultMethods, methodOffset) to block the signals and slots of QObject::staticMetaObject
+    // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
+    int methodOffset = qMax(QObject::staticMetaObject.methodCount(), metaObject->methodOffset());
     int signalOffset = signalCount - QMetaObjectPrivate::get(metaObject)->signalCount;
 
     // update() should have reserved enough space in the vector that this doesn't cause a realloc
@@ -757,8 +758,10 @@ QDeclarativePropertyData qDeclarativePropertyCacheCreate(const QMetaObject *meta
     }
 
     int methodCount = metaObject->methodCount();
-    for (int ii = methodCount - 1; ii >= 3; --ii) {
-        // >=3 to block the destroyed signal and deleteLater() slot
+    int defaultMethods = QObject::staticMetaObject.methodCount();
+    for (int ii = methodCount - 1; ii >= defaultMethods; --ii) {
+        // >=defaultMethods to block the signals and slots of QObject::staticMetaObject
+        // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
         QMetaMethod m = metaObject->method(ii);
         if (m.access() == QMetaMethod::Private)
             continue;