Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Binding loop detection seems very sensitive

Binding loop detection seems very sensitive

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 1 Posters 323 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    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.

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      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.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        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
        }
        

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved