Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problem using Binding QML element
Forum Update on Monday, May 27th 2025

Problem using Binding QML element

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 2 Posters 3.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.
  • AlicemirrorA Offline
    AlicemirrorA Offline
    Alicemirror
    wrote on last edited by
    #1

    Hi to all,

    I am trying to see how the Binding element works but I see in the documentation only examples related to a single bind association. In the documentation I see always examlpes related to QML objects properties and C++ properties exposed to QML. I suppose that it is only one of the possible cases... In a situation like the following example
    @
    Binding {
    target: background
    property: "color"
    value: Methods.getColor("background"); // a js functions
    when: dataParameters.dataReady
    // dataParameres.dataReady is a flag initially set to false
    // that a signal changes to true.
    }

    // The background default color
    Rectangle {
        id: background
        width: parent.width; height: parent.height
    }
    

    @
    if I need to set the binding of my object not only for the color property but also width and height should I create three different Binding instances or I can manage all of them together and how I can do?

    Thank you for any suggestion.

    Enrico Miglino (aka Alicemirror)
    Balearic Dynamics
    Islas Baleares, Ibiza (Spain)
    www.balearicdynamics.com

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      I just open Qt sources for check your question and it seems like one Binding element - one property:

      @class QDeclarativeBindPrivate : public QObjectPrivate
      {
      public:
      QDeclarativeBindPrivate() : when(true), componentComplete(true), obj(0) {}

      bool when : 1;
      bool componentComplete : 1;
      QObject *obj;
      QString prop;
      QDeclarativeNullableValue<QVariant> value;
      

      };
      @

      --
      Vasiliy

      1 Reply Last reply
      0
      • AlicemirrorA Offline
        AlicemirrorA Offline
        Alicemirror
        wrote on last edited by
        #3

        Thank you. This means that is unuseful. In the meanwhile I have analized the general question. The problem is that until a specific element (the configuration parameters) is not loaded any of the parametrized elements can be assigned with the function because it returns an error condition.
        In the case of QML-to-QML the solution is to manage the assignements instead bindings with signals. I saw it more efficient and reliable.

        Enrico Miglino (aka Alicemirror)
        Balearic Dynamics
        Islas Baleares, Ibiza (Spain)
        www.balearicdynamics.com

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vsorokin
          wrote on last edited by
          #4

          May be states can help you.
          Something like:
          @
          // The background default color
          Rectangle {
          id: background
          width: parent.width; height: parent.height

              states: [ State {
                   when: dataParameters.dataReady
                   PropertyChanges {
                        target: background
                        color: Methods.getColor("background"); // a js functions
                   }
                   PropertyChanges {
                        target: foreground
                        color: Methods.getColor("foreground"); // a js functions
                   }
              }
              ]
          }@
          

          --
          Vasiliy

          1 Reply Last reply
          0
          • AlicemirrorA Offline
            AlicemirrorA Offline
            Alicemirror
            wrote on last edited by
            #5

            Thank you Vass :)

            At the moment I have adopted this solution:
            @
            // Header banner
            Framework.Loader {
            id: appTopBanner;
            width: parent.width;
            signal configReady

                onConfigReady: {
                    fontPoints: Methods.jsonConfig.
                    obj_color = Methods.jsonConfig.colors[0].headerMenu;
                    height = Methods.jsonConfig.pixels[0].headerHeight;
                    obj = "TextHeader"
                }
            }
            

            @
            This works and I think it is almost analog to yours. The difference is that I can fire a signal to the whole page and all the childs and subchilds etc. in the inherit tree can catch the same signal.

            You method instead has the advantage that I can join more different targets in the same place.

            What is the best method? What is your opinion ? I am attracted byt both...

            Enrico Miglino (aka Alicemirror)
            Balearic Dynamics
            Islas Baleares, Ibiza (Spain)
            www.balearicdynamics.com

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vsorokin
              wrote on last edited by
              #6

              [quote author="Alicemirror" date="1316331482"]What is the best method? What is your opinion ?[/quote]

              I think it depends on your goals and your preferences.

              --
              Vasiliy

              1 Reply Last reply
              0
              • AlicemirrorA Offline
                AlicemirrorA Offline
                Alicemirror
                wrote on last edited by
                #7

                My thought is that probably the signals are more flexible but a bit more complex because need a signal definition in every object.

                Your method has the advantage that can be managed externally.

                Remain - I think in both cases - the problem that the second level child objects can't be updated directly. Or I am wrong ?

                Enrico Miglino (aka Alicemirror)
                Balearic Dynamics
                Islas Baleares, Ibiza (Spain)
                www.balearicdynamics.com

                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