diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-06-18 09:24:04 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-06-22 14:29:02 +0000 |
commit | 6fe8ed82cdc3e2ec4f6fc9980a41d457b6aed110 (patch) | |
tree | f920dd887bceb224110b50cb6ba09241a7a65f12 /tests/auto/qml/qqmldelegatemodel/data/contextAccessedByHandler.qml | |
parent | 1b2167d935ee19f2cb2c6d7bb0b557e6a8eb3485 (diff) |
Ensure model is in context if required properties are not used
We need to set the set the contextObject already in
QQmlDelegateModelPrivate::object, as the context property might be
accessed in a child component before we are able to run
setRequiredProperties (which would set-up the context in case there are
no required properties).
Instead of delaying setting the context object, we clear it now in
setRequiredProperties.
This has the drawback that one might be able to access context
properties on initial component setup which should not exist
(due to the presence of required properties).
This could be avoided by inspecting the Compilation Unit and only
setting the context if we do not find required properties, however that
needs further work to expose the necessary information.
Fixes: QTBUG-94223
Change-Id: I678de81408539417fc650f94da4c9f0d3167653d
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 58cd06033cacadab541efaa16a3eecec37dab0fa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/qml/qqmldelegatemodel/data/contextAccessedByHandler.qml')
-rw-r--r-- | tests/auto/qml/qqmldelegatemodel/data/contextAccessedByHandler.qml | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmldelegatemodel/data/contextAccessedByHandler.qml b/tests/auto/qml/qqmldelegatemodel/data/contextAccessedByHandler.qml new file mode 100644 index 0000000000..46d7524527 --- /dev/null +++ b/tests/auto/qml/qqmldelegatemodel/data/contextAccessedByHandler.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 + +Item { + id: root + width: 640 + height: 480 + property bool works: myView.currentItem.okay + + ListView { + id: myView + model: myModel + anchors.fill: parent + delegate: Row { + property alias okay: image.isSelected + ImageToggle { + id: image + source: "glyph_16_arrow_patch" + isSelected: model.age < 6 + } + Text { + text: "age:" + model.age + " selected:" + image.isSelected + } + } + } + + ListModel { + id: myModel + ListElement { type: "Cat"; age: 3; } + ListElement { type: "Dog"; age: 2; } + } +} |