Binding loop detection seems very sensitive
-
I found this trivial bind that was created in my code. I wanted to signal off the change of a value that was not a property of value injected by a ListView to a delegate which is called: update_. So I made it assign a value to a property called refresh.
import QtQuick 2.15 import QtQuick.Window 2.15 Window { width: 640 height: 480 visible: true title: qsTr("Binding Loop") property bool bind: true property bool update_: false property bool refresh: update_ onRefreshChanged: { console.log("refresh", refresh) if(refresh){ if(bind){ update_ = false }else{ Qt.callLater(resetUpdate) } } } function resetUpdate(){ update_ = false } Component.onCompleted: update_ = true }
Anytime it changes update_ it will change refresh and trigger the onRefreshChanged. What is interesting to me is that it detects a binding loop on the second call. It seems to me this would be a common use case. So having be this sensitive is also interesting to me. But if I use a Binding {} object or use Qt.callLater I can avoid this binding loop error. I don't remember this being this sensitive before. But I do remember creating binding loops that locked my machine up. So maybe it is for the better.
-
Which begs the question: Can I provide just a signal from a model to a delegate?
I suppose I could change it to an int and just accumulate the change so there is no updating of the value by the detection code. I am already treating it like an event anyway. It is probably an indication of code smell in the design anyway. -
BTW, out of curiosity, I found you can break the detection this way and create programs that will lock up. So be careful:
import QtQuick 2.15 import QtQuick.Window 2.15 Window { width: 640 height: 480 visible: true title: qsTr("Binding Loop") property bool bind: false property bool update_: false property bool refresh: update_ onRefreshChanged: { console.log("refresh", refresh) if(refresh){ if(bind){ update_ = false }else{ Qt.callLater(resetUpdate) } } } function resetUpdate(){ update_ = false //Qt.callLater(()=>{update_ = true}) // can easily break detection } Component.onCompleted: update_ = true }