From 2f87fde9bb4bad6787101c0d135419b350b201a5 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 25 Nov 2013 09:52:02 +0100 Subject: Allow for QtDeclarative and QtQml to co-exist at run-time Qml has a bunch of hooks in QObject, that are callbacks as function pointers when things happen in QObject. QtDeclarative (Qml1) only needs one callback, for object destruction. In preparation for allowing both run-times to co-exist, this patch forks the callback, keeping the "default" variant for QtQml and having a *_qml1 variant for QtDeclarative. QtQml continues to set the callback variable for the default and QtDeclarative will set the _qml1 variant. It is however a limitation that a QObject instance can only be exposed to _one_ engine at a time, and it is not possible to make a transfer. Double exposure will result in crashes. This patch alone is not sufficient to fix the bug, the QQmlData/QDeclarativeData structures in Qml1 and Qml2 need to be extended to allow distinction at run-time. Task-number: QTBUG-35006 Change-Id: I3bac023873b5656a8a4f117fe816bafcda77b67d Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/corelib/kernel/qobject.cpp | 11 ++++++++--- src/corelib/kernel/qobject_p.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 282672ddc7..6ed3b30917 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -177,6 +177,7 @@ private: void (*QAbstractDeclarativeData::destroyed)(QAbstractDeclarativeData *, QObject *) = 0; +void (*QAbstractDeclarativeData::destroyed_qml1)(QAbstractDeclarativeData *, QObject *) = 0; void (*QAbstractDeclarativeData::parentChanged)(QAbstractDeclarativeData *, QObject *, QObject *) = 0; void (*QAbstractDeclarativeData::signalEmitted)(QAbstractDeclarativeData *, QObject *, int, void **) = 0; int (*QAbstractDeclarativeData::receivers)(QAbstractDeclarativeData *, const QObject *, int) = 0; @@ -805,8 +806,12 @@ QObject::~QObject() } } - if (d->declarativeData) - QAbstractDeclarativeData::destroyed(d->declarativeData, this); + if (d->declarativeData) { + if (QAbstractDeclarativeData::destroyed) + QAbstractDeclarativeData::destroyed(d->declarativeData, this); + if (QAbstractDeclarativeData::destroyed_qml1) + QAbstractDeclarativeData::destroyed_qml1(d->declarativeData, this); + } // set ref to zero to indicate that this object has been deleted if (d->currentSender != 0) @@ -1859,7 +1864,7 @@ void QObjectPrivate::setParent_helper(QObject *o) } } } - if (!isDeletingChildren && declarativeData) + if (!isDeletingChildren && declarativeData && QAbstractDeclarativeData::parentChanged) QAbstractDeclarativeData::parentChanged(declarativeData, q, o); } diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index f5745515c9..cd2d592cec 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -90,6 +90,7 @@ class Q_CORE_EXPORT QAbstractDeclarativeData { public: static void (*destroyed)(QAbstractDeclarativeData *, QObject *); + static void (*destroyed_qml1)(QAbstractDeclarativeData *, QObject *); static void (*parentChanged)(QAbstractDeclarativeData *, QObject *, QObject *); static void (*signalEmitted)(QAbstractDeclarativeData *, QObject *, int, void **); static int (*receivers)(QAbstractDeclarativeData *, const QObject *, int); -- cgit v1.2.3