import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
property int anum: 0
property int bnum: 1
onAnumChanged: {
bnum+=1
}
onBnumChanged: {
anum+=1
//Is there some way to stop loop call ?
//in widget we can unconnect some signal and slot
//but how to disconnect in qml
}
Button{
text:"begain"
onClicked: {
anum=anum+1
}
}
}
is there some way to stop this?can i use some unbinding function to stop this like 'disconnect(sender,signal,receiver,slot)' in c++(widget)
Several things are needed to help break the binding loop:
We can borrow the userbreak pattern and implement here with mouse tapped, keypress and even visibility changing as things that will raise a userbreak.
import QtQuick
import QtQuick.Controls
Page {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
property int anum: 0
property int bnum: 1
property bool userbreak: false
onAnumChanged: {
if (userbreak) return;
Qt.callLater( () => { bnum++ } );
}
onBnumChanged: {
if (userbreak) return;
Qt.callLater( () => { anum++ } );
//Is there some way to stop loop call ?
//in widget we can unconnect some signal and slot
//but how to disconnect in qml
}
Button{
text: "begain %1 %2".arg(anum).arg(bnum)
onClicked: {
userbreak = false;
Qt.callLater( () => { anum++ } );
}
}
TapHandler {
onTapped: userbreak = true;
}
Keys.onPressed: {
userbreak = true;
}
onVisibleChanged: {
userbreak = true;
}
}
You can Try it Online!