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. Qml Switch is not updated by model after manual set
QtWS25 Last Chance

Qml Switch is not updated by model after manual set

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 692 Views
  • 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 Offline
    T Offline
    th.thielemann
    wrote on last edited by
    #1

    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
    0
    • T th.thielemann

      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 Offline
      B Offline
      Buttink
      wrote on last edited by
      #2

      @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
      0

      • Login

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