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. How to create a bidirectionnal binding
QtWS25 Last Chance

How to create a bidirectionnal binding

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 2.3k 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.
  • M Offline
    M Offline
    Merinas
    wrote on last edited by
    #1

    Hi,

    I've got two Qml element, each of them has a "test" property and this property must have always the same value. I can use a binding to link one property to another but this is not bidirectional.

    Here an example of what I need.

    @import QtQuick 1.0

    Rectangle{
    id:root

    MyItem{id:a}
    MyItem{id:b}
    

    }@

    Here I want a.test and b.test to to have always the same value.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      grego
      wrote on last edited by
      #2

      Why don't you just have a property alias in a and b that refers to some root element property?

      Grego - http://mpaja.com/

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Merinas
        wrote on last edited by
        #3

        Because this will imply to know the root from my Item. And those items are suppose to be part of separate module (each of them ) so I can't force a use case like this.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Maybe use singal/ slots connections to connect "onChanged" of both objects? You may have to add some clever code to prevent looping, but it's not hard.

          Although I would personally opt for what grego said: a global property, managed by root. As far as I see, it is perfectly doable, even when those objects are separated (some signal/ slot magic might come handy in that case).

          Or use some more fancy stuff, like a shared C++ object, that all MyItems would be connected with. Or database, or a config file... right, I've got to stop right here, as I feel I am getting too abstract ;) I seems that you have to have some control from parent/ root regardless of what option you choose.

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Merinas
            wrote on last edited by
            #5

            thank to you two for your suggestion.

            In fact I've got a solution, I use two binding element, because in my case those properties cannot change in the same time. So I play with the when property. But this doesn't seems right to my, it's look like makeshift job.

            My two modules aren't especially written for my project so I don't want to contaminate them.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Might be good to make this into a feature request on JIRA, then - or even to write your own solution and submit it to Qt-project.

              (Z(:^

              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