Problem using Binding QML element
-
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.
-
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;
};
@ -
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. -
May be states can help you.
Something like:
@
// The background default color
Rectangle {
id: background
width: parent.width; height: parent.heightstates: [ State { when: dataParameters.dataReady PropertyChanges { target: background color: Methods.getColor("background"); // a js functions } PropertyChanges { target: foreground color: Methods.getColor("foreground"); // a js functions } } ] }@
-
Thank you Vass :)
At the moment I have adopted this solution:
@
// Header banner
Framework.Loader {
id: appTopBanner;
width: parent.width;
signal configReadyonConfigReady: { 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...
-
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 ?