Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
6.7.2
-
None
Description
Getting an incorrect property value through a WebChannel inside a WebEngineView
I have an object in qml:
QtObject { id: qmlObj WebChannel.id: "qmlObj" property int testProperty: 0 signal checkTestProperty }
which I then register in the registeredObjects property of the WebChannel object:
WebEngineView {
// ...
webChannel: WebChannel {
id: webChannel
registeredObjects: [qmlObj]
}
}
Next, I change the value of the testProperty property through a button inside the qml:
Button {
id: incrementTestProperty
text: "Increment testProperty"
onClicked: {
qmlObj.testProperty++
qmlObj.checkTestProperty()
console.log(qmlObj.testProperty)
}
}
and then try to get the value of this property from the html/js code that runs inside the WebEngineView in different ways:
qmlObj.testPropertyChanged.connect(() => { console.log("testPropertyChanged", qmlObj.testProperty) }) qmlObj.checkTestProperty.connect(() => { console.log("checkTestProperty", qmlObj.testProperty) }) // ... function buttonClickHandler() { console.log("Button clicked", qmlObj.testProperty) } // ... <button onclick="buttonClickHandler()">Click me</button>
Moreover, after changing the value of the specified property, I explicitly emit the checkTestProperty signal and at the same time I want the handler in html/js to be called and display the value of my property, but at the same time I get the PREVIOUS value of this property, here is an example of the output of all the ways to get this property:
qml: 1 qml: WebEngineView: checkTestProperty 0 qml: WebEngineView: testPropertyChanged 1 qml: 2 qml: WebEngineView: checkTestProperty 1 qml: WebEngineView: testPropertyChanged 2 qml: 3 qml: WebEngineView: checkTestProperty 2 qml: WebEngineView: testPropertyChanged 3 qml: 4 qml: WebEngineView: checkTestProperty 3 qml: WebEngineView: testPropertyChanged 4 qml: WebEngineView: Button clicked 4 qml: WebEngineView: Button clicked 4 qml: WebEngineView: Button clicked 4 qml: WebEngineView: Button clicked 4
I am attaching an archive with a project to demonstrate the described behavior