O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What just happened?

First, we added an import statement to make the QtQuick.Controls module available in the current scope. If you're not sure which version to use, invoke Qt Creator's code completion and use the most recent version. Due to the new import, we can now use the TextField and Label QML types in our QML file.

Next, we declared two children of the top-level Window object. QML objects form a parent-child relationship, much like QObject in C++. However, you don't need to explicitly assign parents to items. Instead, you declare the object within the declaration of its parent, and QML will automatically ensure that relationship. In our example, the TextField { ... } part tells QML to create a new QML object of the TextField type.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required