diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-03-19 10:18:57 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-03-21 08:45:28 +0000 |
commit | aceeec0a85cc50fec70e3142936332a3b09e7061 (patch) | |
tree | 059990158695a886d72bf18e25b5b30c489e2103 /tests | |
parent | ce5b33c350cb7aa4a649088d85e48be08b632b69 (diff) |
Fix crash with StackView::initialItem
The following binding
initialView: Qt.createComponent("blah.qml")
works with QQC1 but crashes with QQC2 as soon as the garbage collector
kicks in. In QQC1 StackView was implemented in a .qml file and the
property was declared as
property var initialItem
For such declared properties the QML engine takes care of ensuring that
the reference assigned is a strong reference towards the GC and it also
tracks the life-time of the QObject in case it's explicitly deleted by
somebody else.
In QQC2 the property continues to be documented as "var" property,
however it is implemented in C++ as QVariant property. The QVariant is
not known to the GC at all and it also doesn't do life-cycle tracking.
The C++ equivalent to "var" in QML is QJSValue, which is a strong
reference and also ends up using a QPointer internally when holding a
QObject.
Task-number: QTBUG-67118
Change-Id: I43e473c7bf2c40f9843e9d50fe4fd805b54fd256
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_stackview.qml | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_stackview.qml b/tests/auto/controls/data/tst_stackview.qml index 3c0f0273..3827354b 100644 --- a/tests/auto/controls/data/tst_stackview.qml +++ b/tests/auto/controls/data/tst_stackview.qml @@ -1230,4 +1230,19 @@ TestCase { touch.release(0, control).commit() verify(!ma.pressed) } + + // Separate function to ensure that the temporary value created to hold the return value of the Qt.createComponent() + // call is out of scope when the caller calls gc(). + function stackViewFactory() + { + return createTemporaryObject(stackView, testCase, {initialItem: Qt.createComponent("TestItem.qml")}) + } + + function test_initalItemOwnership() + { + var control = stackViewFactory() + verify(control) + gc() + verify(control.initialItem) + } } |