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. Order of initialisation for c++/qml object
Forum Updated to NodeBB v4.3 + New Features

Order of initialisation for c++/qml object

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 737 Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Katlin
    wrote on last edited by
    #1

    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).

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Katlin
      wrote on last edited by
      #2

      Note: if I try to access myLabel.label_1 onClick, it works, so after the initalisations, I do have acccess to them.

      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