Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
5.15.11, 6.2.6, 6.4.0
-
Windows 10 Pro 21H2, MSVC 2019 x64
-
dfdba3b12 (dev), 498de3e38 (6.4), 55ca13df5 (6.5), 045e3de7a (tqtc/lts-6.2)
Description
We get different outcomes, depending on whether or not qmlsc is run:
import QtQuick 2.15 import QtQuick.Window 2.15 Window { id: win width: 640 height: 480 visible: true title: "Base State" property var obj: null Rectangle { id: redRect width: 100 height: 100 color: "red" visible: win.obj } Item { states: [ State { id: otherState name: "other" when: win.obj PropertyChanges { target: win title: "Other State" } } ] } // Report variable values, before and after creating object function report() { console.log("win.obj:", win.obj) console.log("redRect.visible:", redRect.visible) console.log("otherState.when:", otherState.when) console.log("win.title:", win.title, '\n') } // Initial report Component.onCompleted: win.report() Timer { interval: 1000 running: true repeat: false onTriggered: { win.obj = Qt.createQmlObject("import QtQml 2.15\nQtObject {}", win, "myDynamicSnippet" ) // Final report win.report() } } }
Output when qmlsc is used (Correct)
qml: win.obj: null qml: redRect.visible: false qml: otherState.when: false qml: win.title: Base State qml: win.obj: QObject(0x1911d2c59b0) qml: redRect.visible: true qml: otherState.when: true qml: win.title: Other State
Output when qmlcachegen is used, or when bytecode compilation is disabled altogether (Wrong)
qml: win.obj: null qml: redRect.visible: false qml: otherState.when: false qml: win.title: Base State qml: win.obj: QObject(0x1a958155510) qml: redRect.visible: true qml: otherState.when: true qml: win.title: Base State
Workaround
Explicitly coerce the object into a Boolean value:
- win.obj !== null
- Boolean(win.obj)
Attachments
Issue Links
- relates to
-
QTBUG-105000 [REG: 5.15.2->5.15.10] State.when does not work for objects anymore
- Closed