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. Two bindings for the same property?
Qt 6.11 is out! See what's new in the release blog

Two bindings for the same property?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 308 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.
  • D Offline
    D Offline
    DaveMilter
    wrote on last edited by
    #1

    I want two binding for the same field, one default,
    and other should replace default and then restore it back.

    As I understand Qt/QML can do it: https://doc.qt.io/qt-5/qml-qtqml-binding.html via restoreMode : Binding.RestoreBinding .

    But for some reason it doesn't work.
    I create static binding: cfg_flag1 -> flag1, then I create temporary binding true -> flag1and destroy this binding, then I setcfg_flag1 = falseand I expect that via restored bindingcfg_flag1 -> flag1 flag1gotfalse`. But for some reason the static binding do not work anymore.
    Any idea about how RestoreBinding works?

    import QtQuick 2.0
    import QtQuick.Controls 2.15
    
    Rectangle {
        id: rect
        width: 100
        height: 100
        color: "red"
    
        property bool flag1: {
            console.log("set flag1 to", cfg_flag1);
            return cfg_flag1;
        }
        property bool cfg_flag1: true
    
        Text {
            anchors.centerIn: parent
            text: "flag1: " + flag1.toString() + ", cfg_flag1 " + cfg_flag1.toString()
        }
    
        Timer {
            id: timer
            interval: 1000
            repeat: false
            onTriggered: {
                console.log("timer trigger");
                cfg_flag1 = false;
            }
        }
    
        Button {
            anchors.top: parent.top
            text: "button 1"
            onClicked: {
                console.log("buggon1 cliecked");
                let temp = cmpBinding.createObject(rect, {
                    "target": rect,
                    "property": "flag1",
                    "value": true,
                    "restoreMode": Binding.RestoreBinding,
                });
                temp.Component.onDestruction.connect(function() { console.log("destroyed"); });
                temp.destroy();
                console.log("end of clicked");
                timer.start();
            }
        }
    
        Component {
            id: cmpBinding
    
            Binding {
            }
    
        }
    }
    
    1 Reply Last reply
    1

    • Login

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