diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-01-27 12:05:09 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-01-31 11:52:53 +0100 |
commit | b04776e82eaa0fdda1ede1b5635844eddc6c3501 (patch) | |
tree | 4b1b39e750f7b18193113399193d5eb16c2a8478 /src | |
parent | d31e86f8066bf5d47c480105d579d53ae223aabf (diff) |
Item views: Don't create unnecessary QML contexts
Bound components can only be instantiated in the context they're
declared in. Adding a context in between before instantiating a
component makes it impossible to bind the component. We want to use
bound components so that we can safely use IDs of other objects from
the same context inside the objects created from the component.
See also commit fc683799fee933757abdd3953048f136e750690b.
Pick-to: 6.5
Fixes: QTBUG-110697
Change-Id: I8ac9afe13a3d88a4c8e432f5cd701abee8a7f6ac
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickitemview.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index 1f3ec79190..a149f8d098 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -2447,17 +2447,14 @@ QQuickItem *QQuickItemViewPrivate::createComponentItem(QQmlComponent *component, QQuickItem *item = nullptr; if (component) { - QQmlContext *creationContext = component->creationContext(); - QQmlContext *context = new QQmlContext( - creationContext ? creationContext : qmlContext(q)); - QObject *nobj = component->beginCreate(context); - if (nobj) { - QQml_setParent_noEvent(context, nobj); + QQmlContext *context = component->creationContext(); + if (!context) + context = qmlContext(q); + + if (QObject *nobj = component->beginCreate(context)) { item = qobject_cast<QQuickItem *>(nobj); if (!item) delete nobj; - } else { - delete context; } } else if (createDefault) { item = new QQuickItem; |