Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Qml Switch is not updated by model after manual set

    QML and Qt Quick
    2
    2
    523
    Loading More Posts
    • 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.
    • T
      th.thielemann last edited by

      In qml I have a Switch connected with a c++ bool

      Q_PROPERTY(bool boolValue READ getBoolValue WRITE setBoolValue NOTIFY boolValueChanged)

      If I execute the app, the Switch shows the current state of the property. I added a QTimer in c++ to set the boolValue every second. The Qml Switch toggles to. But as soon as I set the Switch in Qml, it does not toggle anymore.
      Is this the expected behaviour or an error?

      Same behaviour with the following two Switches: Slave follows master until slave was set by the user.

                  Switch {
                      id: masterSwitch
                  }
                  Switch {
                      id: slave
                      checked: masterSwitch.checked
                  }
      

      Regards,
      Thomas

      B 1 Reply Last reply Reply Quote 0
      • B
        Buttink @th.thielemann last edited by

        @th.thielemann Pretty sure this is expected. You need to say something more like

                    Switch {
                        id: masterSwitch
                        onCheckedChanged: { slave.checked = checked }
                    }
                    Switch {
                        id: slave
                    }
        

        Because you destroy your binding when the switch does its own assignment.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post