Forums

OverviewV-Play 2 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
    V-Play Team
    #8621

    Martin

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

    I think that somewhere in the V-Play 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 V-Play as the starting point.

     

     

    #8631

    Christian
    V-Play 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 V-Play 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
    V-Play 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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support