Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.10
-
None
Description
Sometimes, it is inevitable that we might need to explicitly capture extra properties in a binding:
import QtQuick import QtQuick.Window Window { id: window width: 320 height: 320 visible: true readonly property var globalPos: { window.x; window.y; return contentItem.mapToGlobal(0, 0); } onGlobalPosChanged: console.log(globalPos.x, globalPos.y) }
Codes above work well with Qt 5, while on Qt 6 the globalPos property no longer get evaluated when moving the window.
Interestingly, we can workaround this issue with these magic:
readonly property point globalPos: { // only changing property type window.x; window.y; return contentItem.mapToGlobal(0, 0); }
or
readonly property var globalPos: { window.x; window.y; const p = contentItem.mapToGlobal(0, 0); return { x: p.x, y: p.y }; }
or less magic
function unused_reference() {} readonly property point globalPos: { // only changing property type unused_reference(window.x, window.y); return contentItem.mapToGlobal(0, 0); }
Does explicitly capturing syntax still work with Qt 6? Or should such trick never be used on any versions of Qt?