From 7fffd12ab19278ce0f91f490c9070905ec4f2c28 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 6 Jul 2017 11:33:08 +0200 Subject: QQuickContainer: use get() instead of QQmlListProperty::data for d-ptr MSVC2015 has very strange issues with QQmlListProperty::data in release builds. The pointer is somehow lost between constructing the object and when it reaches a list-property function. It's probably somehow related to the qSwap() calls in QQmlObjectCreator::setupBindings(), but this is tricky to investigate, because adding qDebug() output anywhere near the qSwap() calls also makes the problem disappear. It's easier to use the standard Private::get() pattern instead. :) Change-Id: Iaa361f07023820bfe38191a100cebf64fadb4d62 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickcontainer.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/quicktemplates2/qquickcontainer.cpp') diff --git a/src/quicktemplates2/qquickcontainer.cpp b/src/quicktemplates2/qquickcontainer.cpp index eaf18714..a62de655 100644 --- a/src/quicktemplates2/qquickcontainer.cpp +++ b/src/quicktemplates2/qquickcontainer.cpp @@ -370,8 +370,8 @@ void QQuickContainerPrivate::itemDestroyed(QQuickItem *item) void QQuickContainerPrivate::contentData_append(QQmlListProperty *prop, QObject *obj) { - QQuickContainerPrivate *p = static_cast(prop->data); QQuickContainer *q = static_cast(prop->object); + QQuickContainerPrivate *p = QQuickContainerPrivate::get(q); QQuickItem *item = qobject_cast(obj); if (item) { if (QQuickItemPrivate::get(item)->isTransparentForPositioner()) @@ -385,20 +385,20 @@ void QQuickContainerPrivate::contentData_append(QQmlListProperty *prop, int QQuickContainerPrivate::contentData_count(QQmlListProperty *prop) { - QQuickContainerPrivate *p = static_cast(prop->data); - return p->contentData.count(); + QQuickContainer *q = static_cast(prop->object); + return QQuickContainerPrivate::get(q)->contentData.count(); } QObject *QQuickContainerPrivate::contentData_at(QQmlListProperty *prop, int index) { - QQuickContainerPrivate *p = static_cast(prop->data); - return p->contentData.value(index); + QQuickContainer *q = static_cast(prop->object); + return QQuickContainerPrivate::get(q)->contentData.value(index); } void QQuickContainerPrivate::contentData_clear(QQmlListProperty *prop) { - QQuickContainerPrivate *p = static_cast(prop->data); - p->contentData.clear(); + QQuickContainer *q = static_cast(prop->object); + return QQuickContainerPrivate::get(q)->contentData.clear(); } void QQuickContainerPrivate::contentChildren_append(QQmlListProperty *prop, QQuickItem *item) @@ -409,8 +409,8 @@ void QQuickContainerPrivate::contentChildren_append(QQmlListProperty int QQuickContainerPrivate::contentChildren_count(QQmlListProperty *prop) { - QQuickContainerPrivate *p = static_cast(prop->data); - return p->contentModel->count(); + QQuickContainer *q = static_cast(prop->object); + return QQuickContainerPrivate::get(q)->contentModel->count(); } QQuickItem *QQuickContainerPrivate::contentChildren_at(QQmlListProperty *prop, int index) @@ -421,8 +421,8 @@ QQuickItem *QQuickContainerPrivate::contentChildren_at(QQmlListProperty *prop) { - QQuickContainerPrivate *p = static_cast(prop->data); - p->contentModel->clear(); + QQuickContainer *q = static_cast(prop->object); + return QQuickContainerPrivate::get(q)->contentModel->clear(); } QQuickContainer::QQuickContainer(QQuickItem *parent) @@ -623,8 +623,7 @@ QVariant QQuickContainer::contentModel() const */ QQmlListProperty QQuickContainer::contentData() { - Q_D(QQuickContainer); - return QQmlListProperty(this, d, + return QQmlListProperty(this, nullptr, QQuickContainerPrivate::contentData_append, QQuickContainerPrivate::contentData_count, QQuickContainerPrivate::contentData_at, @@ -647,8 +646,7 @@ QQmlListProperty QQuickContainer::contentData() */ QQmlListProperty QQuickContainer::contentChildren() { - Q_D(QQuickContainer); - return QQmlListProperty(this, d, + return QQmlListProperty(this, nullptr, QQuickContainerPrivate::contentChildren_append, QQuickContainerPrivate::contentChildren_count, QQuickContainerPrivate::contentChildren_at, -- cgit v1.2.3