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
}
}
}
有什么方法可以阻止这个吗?我可以使用一些解除绑定函数来阻止这个,比如c++(小部件)中的“断开(发送者,信号,接收者,插槽)”
需要一些东西来帮助打破绑定循环:
我们可以借用用户中断模式并通过鼠标点击、按键甚至可见性更改来实现,这些都会引发用户中断。
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;
}
}
您可以在线尝试!