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?

You can see that we have a new file called Button.qml in the project, which contains everything the button item used to have, with the exception of the id and anchors.centerIn properties. The main file was simplified to the following:

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Button {
        id: button        anchors.centerIn: parent
    }
}

Button has become a component—a definition of a new type of element that can be used the same way as standard QML element types. Remember that QML component names, as well as names of files representing them, need to begin with a capital letter! If you name a file button.qml instead of Button.qml, then you will not be able to use Button as a component name, and trying ...

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