Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122707

[Reg 5.15 -> 6.4] Binding QML type does not restore original value in some cases

    XMLWordPrintable

Details

    • Linux/X11
    • 98ecc9adb (dev), a262824c2 (6.7), ae9905b0c (6.6), 7cfd1ac42 (tqtc/lts-6.5)

    Description

      In case when we have initial binding to some "var" property with function and trying to change this binding using Binding QML type to another function restoring of original value will not happen after Binding was activated twice (same with arrays).

      Please take a look at the video: simplescreenrecorder-2024-02-24_00.19.01.mkv

      First row is function replaced by binding to another function. As you can see after change is done twice original value is never restored.
      Second row is about array and there is the same issue.
      Third row about array, but original value is not plain value, but a binding and everything works fine.
      Fourth row about function, but value inside the Binding component is null instead of another function and in this case everything works as expected as well

      Please see the example from the video:

       

      import QtQuick
      import QtQuick.Controls
      Window {
          width: 640
          height: 800
          visible: true
          title: qsTr("Hello World")
          Item {
              id: root
              width: parent.width
              height: 200
              property var func: function() {
                  console.log("func original");
              }
              property bool funcSwitcher: false
              Binding {
                  root.func: function() {
                      console.log("func imposter");
                  }
                  when: root.funcSwitcher
                  restoreMode: Binding.RestoreBindingOrValue
              }
              Row {
                  Button {
                      text: "call func"
                      onClicked: {
                          root.func();
                      }
                  }
                  Button {
                      text: "switch func isImposter: " + root.funcSwitcher
                      onClicked: {
                          root.funcSwitcher = !root.funcSwitcher;
                      }
                  }
              }
          }
          Item {
              id: root2
              anchors.top: root.bottom
              width: parent.width
              height: 200
              property var func: [1, 2, 3]
              property bool funcSwitcher: false
              Binding {
                  root2.func: [1, 2]
                  when: root2.funcSwitcher
                  restoreMode: Binding.RestoreBindingOrValue
              }
              Row {
                  Button {
                      text: "call func"
                      onClicked: {
                          console.log(root2.func)
                      }
                  }
                  Button {
                      text: "switch func isImposter: " + root2.funcSwitcher
                      onClicked: {
                          root2.funcSwitcher = !root2.funcSwitcher;
                      }
                  }
              }
          }
          Item {
              id: root3
              anchors.top: root2.bottom
              width: parent.width
              height: 200
              property var func: !root3.funcSwitcher ? [1, 2, 3] : []
              property bool funcSwitcher: false
              Binding {
                  root3.func: [1, 2]
                  when: root3.funcSwitcher
                  restoreMode: Binding.RestoreBindingOrValue
              }
              Row {
                  Button {
                      text: "call func"
                      onClicked: {
                          console.log(root3.func)
                      }
                  }
                  Button {
                      text: "switch func isImposter: " + root3.funcSwitcher
                      onClicked: {
                          root3.funcSwitcher = !root3.funcSwitcher;
                      }
                  }
              }
          }
          Item {
              id: root4
              anchors.top: root3.bottom
              width: parent.width
              height: 200
              property var func: function() {
                  console.log("func original");
              }
              property bool funcSwitcher: false
              Binding {
                  root4.func: null
                  when: root4.funcSwitcher
                  restoreMode: Binding.RestoreBindingOrValue
              }
              Row {
                  Button {
                      text: "call func"
                      onClicked: {
                          root4.func();
                      }
                  }
                  Button {
                      text: "switch func isImposter: " + root4.funcSwitcher
                      onClicked: {
                          root4.funcSwitcher = !root4.funcSwitcher;
                      }
                  }
              }
          }
      }
      

       

       

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            fabiankosmale Fabian Kosmale
            dmartyniuk Dmytro Martyniuk
            Votes:
            5 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes