Delaying item creation

Another recurring scenario is that you do know how many elements you will need, but the problem is that you cannot determine upfront what type of elements they will be. At some point during the lifetime of your application, you will learn that information and will be able to instantiate an object. Until you gain the knowledge about the given component, you will need some kind of item placeholder where you will later put the real item. You can, of course, write some code to use the createObject() functionality of the component, but this is cumbersome.

Fortunately, Qt Quick offers a nicer solution in the form of a Loader item. This item type is exactly what we described it to be—a temporary placeholder for a real item ...

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.