Q_GLOBAL_STATIC(AccessorProperties, accessorProperties)
-QML_PRIVATE_ACCESSOR(QObject, QString, objectName, objectName)
-
-static void QObject_objectNameNotifier(QObject *object, intptr_t, QQmlNotifier **notifier)
-{
- *notifier = QQmlData::get(object, true)->objectNameNotifier();
-}
-
-static QQmlAccessors QObject_objectName = { QObject_objectNameRead,
- QObject_objectNameNotifier };
-
-QML_DECLARE_PROPERTIES(QObject) {
- { QML_PROPERTY_NAME(objectName), 0, &QObject_objectName }
-};
-
static void buildNameMask(QQmlAccessorProperties::Properties &properties)
{
quint32 mask = 0;
AccessorProperties::AccessorProperties()
{
- // Pre-seed QObject::objectName accessor
- typedef QQmlAccessorProperties::Properties P;
- properties.insert(&QObject::staticMetaObject,
- P(qqml_accessor_properties_QObject,
- sizeof(qqml_accessor_properties_QObject) /
- sizeof(QQmlAccessorProperties::Property)));
}
QQmlAccessorProperties::Properties::Properties(Property *properties, int count)
initialized = true;
QAbstractDeclarativeData::destroyed = destroyed;
QAbstractDeclarativeData::parentChanged = parentChanged;
- QAbstractDeclarativeData::objectNameChanged = objectNameChanged;
QAbstractDeclarativeData::signalEmitted = signalEmitted;
QAbstractDeclarativeData::receivers = receivers;
}
static void destroyed(QAbstractDeclarativeData *, QObject *);
static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *);
- static void objectNameChanged(QAbstractDeclarativeData *, QObject *);
static void signalEmitted(QAbstractDeclarativeData *, QObject *, int, void **);
static int receivers(QAbstractDeclarativeData *, const QObject *, int);
void destroyed(QObject *);
void parentChanged(QObject *, QObject *);
- void objectNameChanged(QObject *);
void setImplicitDestructible() {
if (!explicitIndestructibleSet) indestructible = false;
}
bool hasExtendedData() const { return extendedData != 0; }
- QQmlNotifier *objectNameNotifier() const;
QHash<int, QObject *> *attachedProperties() const;
static inline bool wasDeleted(QObject *);
static inline void setQueuedForDeletion(QObject *);
private:
- // For objectNameNotifier and attachedProperties
+ // For attachedProperties
mutable QQmlDataExtended *extendedData;
};
static_cast<QQmlData *>(d)->parentChanged(o, p);
}
-void QQmlData::objectNameChanged(QAbstractDeclarativeData *d, QObject *o)
-{
- static_cast<QQmlData *>(d)->objectNameChanged(o);
-}
-
void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int index, void **a)
{
QQmlData *ddata = QQmlData::get(object, false);
~QQmlDataExtended();
QHash<int, QObject *> attachedProperties;
- QQmlNotifier objectNameNotifier;
};
QQmlDataExtended::QQmlDataExtended()
return notifyList && (notifyList->connectionMask & (1ULL << quint64(index % 64)));
}
-QQmlNotifier *QQmlData::objectNameNotifier() const
-{
- if (!extendedData) extendedData = new QQmlDataExtended;
- return &extendedData->objectNameNotifier;
-}
-
QHash<int, QObject *> *QQmlData::attachedProperties() const
{
if (!extendedData) extendedData = new QQmlDataExtended;
Q_UNUSED(parent);
}
-void QQmlData::objectNameChanged(QObject *)
-{
- if (extendedData) objectNameNotifier()->notify();
-}
-
bool QQmlData::hasBindingBit(int bit) const
{
if (bindingBitsSize > bit)
QQmlAccessorProperties::Properties accessorProperties;
- // Special case QObject as we don't want to add a qt_HasQmlAccessors classinfo to it
- if (metaObject == &QObject::staticMetaObject) {
- accessorProperties = QQmlAccessorProperties::properties(metaObject);
- } else if (classInfoCount) {
+ if (classInfoCount) {
int classInfoOffset = metaObject->classInfoOffset();
bool hasFastProperty = false;
for (int ii = 0; ii < classInfoCount; ++ii) {
}
}
- // 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());
+ //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 methodOffset = 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
signalHandlerIndexCache.resize(signalCount - signalHanderIndexCacheStart);
int signalHandlerIndex = signalOffset;
for (int ii = methodOffset; ii < methodCount; ++ii) {
+ if (ii == destroyedIdx1 || ii == destroyedIdx2 || ii == deleteLaterIdx)
+ continue;
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
continue;
}
}
+ //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();
- 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.
+ 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;
return rv;
}
- if (ep && !result->isConstant()) {
-
- if (result->coreIndex == 0)
- ep->captureProperty(QQmlData::get(object, true)->objectNameNotifier());
- else
- ep->captureProperty(object, result->coreIndex, result->notifyIndex);
- }
+ if (ep && !result->isConstant())
+ ep->captureProperty(object, result->coreIndex, result->notifyIndex);
if (result->isVMEProperty()) {
typedef QQmlVMEMetaObject VMEMO;
--- /dev/null
+import QtQuick 2.0
+
+QtObject {
+ id: root
+ onDestroyed: {} //this should cause an error (destroyed should be hidden)
+}
--- /dev/null
+import QtQuick 2.0
+
+QtObject {
+ id: root
+ property bool test: false
+
+ onObjectNameChanged: test = true
+}
void qobjectConnectionListExceptionHandling();
void nonscriptable();
void deleteLater();
+ void objectNameChangedSignal();
+ void destroyedSignal();
void in();
void typeOf();
void qtbug_24448();
delete o;
}
+// objectNameChanged() should be usable from QML
+void tst_qqmlecmascript::objectNameChangedSignal()
+{
+ QQmlComponent component(&engine, testFileUrl("objectNameChangedSignal.qml"));
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+ QCOMPARE(o->property("test").toBool(), false);
+ o->setObjectName("obj");
+ QCOMPARE(o->property("test").toBool(), true);
+ delete o;
+}
+
+// destroyed() should not be usable from QML
+void tst_qqmlecmascript::destroyedSignal()
+{
+ QQmlComponent component(&engine, testFileUrl("destroyedSignal.qml"));
+ QVERIFY(component.isError());
+
+ QString expectedErrorString = component.url().toString() + QLatin1String(":5:5: Cannot assign to non-existent property \"onDestroyed\"");
+ QCOMPARE(component.errors().at(0).toString(), expectedErrorString);
+}
+
void tst_qqmlecmascript::in()
{
QQmlComponent component(&engine, testFileUrl("in.qml"));