What just happened?

First, we created a property called rods that will hold an array of created Rod objects. Next, we used the Component.onCompleted attached property to run some JavaScript code after the QML engine instantiates our root object. Our first action was to load the Rod component and check whether it was loaded successfully. After obtaining a functioning component object, we used its createObject() method to create three new rods. We used the arguments of this function to pass the root object and value of the index property. Finally, we pushed the Rod object into the array.

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.