O'Reilly logo

Qt 5 Projects by Marco Piccolino

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

A short QML primer

Here is what a simple QML document looks like:

import QtQml 2.2QtObject {    id: myQmlObject    readonly property real myNumber: {        return Math.random() + 1    }    property int myNumber2: myNumber + 1    property var myChildObject: QtObject {}    signal done(string message)    onDone: {        print(message);        doSomething();    }    function doSomething() {        print("hello again!");    }    Component.onCompleted: {        console.log("Hello World! %1 %2".arg(myNumber).arg(myNumber2))        done("I'm done!")    }}

Yes, it's got curly braces and colons, but it's not JSON. If you run this document, you'll see nothing but a couple of print statements:

qml: Hello World! 1.88728 2qml: I'm done!qml: Hello again!
You can run this snippet in Qt Creator by creating a new QML document (New ...

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