Order of initialisation for c++/qml object
-
Let's consider the following class, made available in QML:
@
class XLabel : public QQuickText
{
Q_OBJECT
Q_PROPERTY(QQuickText *label_1 READ getLabel1 WRITE setLabel1 NOTIFY label1Changed)
Q_PROPERTY(QQuickText label_2 READ getLabel2 WRITE setLabel2 NOTIFY label2Changed)
/ the 6 functions for these props exist, I've just not pasted them here */
public:
QQuickText *probe, *label1, *label2;
void createLabels();
....
}void XLabel::createLabels(){ label1 = new QQuickText(this); label2 = new QQuickText(this); // here the equivalent of property alias ... } void XLabel::componentComplete(){ createLabels(); QQuickText::componentComplete(); }
@
And used like this in a QML:
@
XLabel{
id:myLabel;In_Fade{
delay : 0;
animationDuration : 1000;
animationEasing : Easing.InOutSine;
animationTarget : myLabel.label_1;
}
}
@The In_Fade is a SequentialAnimation.
Problem: animationTarget is undefined in the onCompleted of In_Fade and null inside a child of In_Fade. How can I have it available in both places?
So this made me ask about the order of initialisations in this particular case.
What I've noticed so far is that the c++ componentComplete is executed before the QML Component.onCompleted (both of the XLabel). -
Note: if I try to access myLabel.label_1 onClick, it works, so after the initalisations, I do have acccess to them.