diff options
author | Wieland Hagen <wieland.hagen@kdab.com> | 2016-12-22 17:35:07 +0700 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2017-01-05 08:44:39 +0000 |
commit | f4ad38facc1a7c4f4f0239f808183b3c24e037ba (patch) | |
tree | c87a27dcd6f83e5c906f7a005fed3a559dc72cee /src/core/nodes/qnode.cpp | |
parent | eb2bfbbce7fd5f0aa9e7d9744487c3d3ac3bb9d2 (diff) |
QNode: Defer QScene registration until after object construcion
We used to call m_scene->addObservable() from the ctor of QNode.
This would lead to the QScene calling QNode::setArbiter(), which in
turn calls QNodePrivate::registerNotifiedProperties(). This method
relies on the meta-class of 'this' in order to connect the
property change listener to all property change signals. So, since
the QNode instance is not yet initialized properly, no connections
are made at all and no property update notifications will work.
This patch fixes this issue by deferring the call to after object
construction.
Change-Id: I45ef46c416f88a84ca55c9b9833312d0fd433d0e
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/nodes/qnode.cpp')
-rw-r--r-- | src/core/nodes/qnode.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp index 8dbcb295a..e4bb5d4a3 100644 --- a/src/core/nodes/qnode.cpp +++ b/src/core/nodes/qnode.cpp @@ -97,10 +97,8 @@ void QNodePrivate::init(QNode *parent) m_scene = parentPrivate->m_scene; Q_Q(QNode); if (m_scene) { - m_scene->addObservable(q); // Sets the m_changeArbiter to that of the scene - - // Scehdule the backend notification - QMetaObject::invokeMethod(q, "_q_notifyCreationAndChildChanges", Qt::QueuedConnection); + // schedule the backend notification and scene registering -> set observers through scene + QMetaObject::invokeMethod(q, "_q_postConstructorInit", Qt::QueuedConnection); } } @@ -166,8 +164,10 @@ void QNodePrivate::notifyDestructionChangesAndRemoveFromScene() * parent backend node of its new child. This is called in a deferred manner * by the QNodePrivate::init() method to notify the backend of newly created * nodes with a parent that is already part of the scene. + * + * Also notify the scene of this node, so it may set it's change arbiter. */ -void QNodePrivate::_q_notifyCreationAndChildChanges() +void QNodePrivate::_q_postConstructorInit() { Q_Q(QNode); @@ -176,6 +176,9 @@ void QNodePrivate::_q_notifyCreationAndChildChanges() if (!parentNode) return; + if (m_scene) + m_scene->addObservable(q); // Sets the m_changeArbiter to that of the scene + // Let the backend know we have been added to the scene notifyCreationChange(); @@ -187,7 +190,7 @@ void QNodePrivate::_q_notifyCreationAndChildChanges() /*! * \internal * - * Called by _q_setParentHelper() or _q_notifyCreationAndChildChanges() + * Called by _q_setParentHelper() or _q_postConstructorInit() * on the main thread. */ void QNodePrivate::_q_addChild(QNode *childNode) |