Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › "Component.onCompleted"

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #8607

    Martin

    I stumbled across this way of doing things at the completion of construction of components – for example doing stuff programmatically at the completion of constructing a level:

    LevelBase {
        levelName: "Level1"
    
        function addPlatform() {
              // ...
        }
    
        // background
        Image {
            anchors.fill: parent
            source: "../../assets/img/bamboo.png";
        }    
    
        Component.onCompleted: {
            addPlatform('startPlatform')
        }
    }

     

    Could someone explain what this “means”.   I know what it _does_, I just don’t know how it does it.   Is it saying “My LevelBase object has Component in its hierarchy, and Component has onCompleted, so I am setting my inherited onCompleted method to be this function”?

    Why is it necessary to specify the “path” to “onCompleted”?   If I am inheriting from Component, then why can’t I just refer to my inherited method?

    And if I’m not inheriting from Component, then … what is the meaning of this declaration?

     

    #8620

    Alex
    Felgo Team
    #8621

    Martin

    Thanks Alex – that’s a very helpful page, and certainly answered my question.

    I think that somewhere in the Felgo docs it would be helpful to have a pointer to this page, for people who aren’t familiar with Qt and are starting (as I am) with Felgo as the starting point.

     

     

    #8631

    Christian
    Felgo Team

    Hi Martin,

    the Component.onCompleted (in other programming languages called the constructor) is one of the very rare cases attached signal handlers are used and is an advanced concept to understand. Thus we did not highlight or mention it explicitly somewhere in the Felgo docs – maybe we could write an “Advanced QML language concepts with examples” document in future if the demand also of other developers is high enough.

    Cheers, Chris

    #8632

    Martin

    Just in the spirit of discussion – it strikes me that attached signal handlers are indeed an advanced concept, but constructors are not: constructors are something that most modern programming languages have.

    And for this reason – they are something that one goes looking for!   I had to hunt quite hard to find this method of “constructor definition”, and (in another thread 🙂 ) I still haven’t found one for scene/level “construction”.

    So IMHO it would be quite natural to tell programmers about the existence of contructors in QML: not under the heading of “Advanced QML concepts”, but rather under the heading of “basic language concepts you’ll go looking for” 😉

    Just entirely IMHO, of course 🙂

    #8673

    Christian
    Felgo Team

    Good point, I agree with you!

    I think we mention it in the tutorials a couple of times, however an extra document would not hurt of course.

    Thanks for bringing that up!

    Cheers, Chris

Viewing 6 posts - 1 through 6 (of 6 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded