From aceeec0a85cc50fec70e3142936332a3b09e7061 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 19 Mar 2018 10:18:57 +0100 Subject: 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 --- src/quicktemplates2/qquickstackview_p.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/quicktemplates2/qquickstackview_p.h') diff --git a/src/quicktemplates2/qquickstackview_p.h b/src/quicktemplates2/qquickstackview_p.h index e347ba9d..ba6fe106 100644 --- a/src/quicktemplates2/qquickstackview_p.h +++ b/src/quicktemplates2/qquickstackview_p.h @@ -65,7 +65,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickStackView : public QQuickControl Q_PROPERTY(bool busy READ isBusy NOTIFY busyChanged FINAL) Q_PROPERTY(int depth READ depth NOTIFY depthChanged FINAL) Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) - Q_PROPERTY(QVariant initialItem READ initialItem WRITE setInitialItem FINAL) + Q_PROPERTY(QJSValue initialItem READ initialItem WRITE setInitialItem FINAL) Q_PROPERTY(QQuickTransition *popEnter READ popEnter WRITE setPopEnter NOTIFY popEnterChanged FINAL) Q_PROPERTY(QQuickTransition *popExit READ popExit WRITE setPopExit NOTIFY popExitChanged FINAL) Q_PROPERTY(QQuickTransition *pushEnter READ pushEnter WRITE setPushEnter NOTIFY pushEnterChanged FINAL) @@ -93,8 +93,8 @@ public: }; Q_ENUM(Status) - QVariant initialItem() const; - void setInitialItem(const QVariant &item); + QJSValue initialItem() const; + void setInitialItem(const QJSValue &item); QQuickTransition *popEnter() const; void setPopEnter(QQuickTransition *enter); -- cgit v1.2.3