Fix crash with early QObject property access
authorSimon Hausmann <simon.hausmann@digia.com>
Thu, 21 Aug 2014 11:10:33 +0000 (13:10 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 25 Aug 2014 13:42:15 +0000 (15:42 +0200)
commitb0835b31fd456c30ea3fcaae6edc58212556477d
tree8155e71cc556ebbe0a7a13128a3fdd1b7eabd152
parent9fcb883aab0e9fc7d87484710fbb6f363dcf4e1f
Fix crash with early QObject property access

In the reported bug, it can happen that we try to access the compile-time resolved
QObject property of an object that is referenced by id. The binding that uses this is
triggered when the property changes but _also_ when the id referenced object gets either
created or deleted. The first time the binding is evaluated is very early on, when the
id referenced object is not created yet, so the binding evaluation fails. However the
dependency is set up, and so later then the id referenced object is created and the id
property is set on the context, the notification triggers and the binding is re-evaluated.
During that binding evaluation a QObject property access happens by index on an object that
doesn't have its VME meta-object set up yet. Therefore the property access fails and a
crash occurs or the Q_ASSERT(property) assertion fails.

The fix is to set register the id named object in the context _after_ the VME meta-object is
setup.

Task-number: QTBUG-40018
Change-Id: Ic2d7b4a0c49635efe68e93f2f6c316eb65f0c309
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/qqmlobjectcreator.cpp
src/qml/qml/qqmlobjectcreator_p.h
tests/auto/qml/qqmllanguage/data/earlyIdObjectAccess.qml [new file with mode: 0644]
tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp