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 <Friedemann.Kleint@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Simon Hausmann 2013-11-25 09:52:02 +01:00 committed by The Qt Project
parent eafa224c3b
commit 2f87fde9bb
2 changed files with 9 additions and 3 deletions

View File

@ -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);
}

View File

@ -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);