Some syntax examples follow:
Objects are specified by their type, followed by a pair of braces. Object types always begin with a capital letter. In the example above, there are two objects, a Rectangle; and its child, an Image. Between the braces, one can specify information about the object, such as its properties. Properties are specified as property: value. In the example above, the Image has a property named source, which has been assigned the value pics/logo.png. The property and its value are separated by a colon.
The id property
Each object can be given a special unique property called an id. Assigning an id enables the object to be referred to by other objects and scripts. The first Rectangle element below has an id, myRect. The second Rectangle element defines its own width by referring to myRect.width, which means it will have the same width value as the first Rectangle element.
An id must begin with a lower-case letter or an underscore, and can contain no characters other than letters, digits, and underscores.
A property binding specifies the value of a property in a declarative way. The property value is automatically updated if the other properties or data values change, following the reactive programming paradigm.
Property bindings are created implicitly in QML whenever a property is assigned a JavaScript expression. The following QML uses two property bindings to connect the size of the rectangle to that of otherItem.
QML extends a standards-compliant JavaScript engine, so any valid JavaScript expression can be used as a property binding. Bindings can access object properties, make function calls, and even use built-in JavaScript objects like Date and Math.
States are a mechanism to combine changes to properties in a semantic unit. A button for example has a pressed and a non-pressed state, an address book application could have a read-only and an edit state for contacts. Every element has an "implicit" base state. Every other state is described by listing the properties and values of those elements which differ from the base state.
Example: In the default state, myRect is positioned at 0,0. In the "moved" state, it is positioned at 50,50. Clicking within the mouse area changes the state from the default state to the "moved" state, thus moving the rectangle.
State changes can be animated using Transitions.
For example, adding this code to the above Item element animates the transition to the "moved" state:
Animations in QML are done by animating properties of objects. Properties of type real, int, color, rect, point, size, and vector3d can all be animated.
QML supports three main forms of animation: basic property animation, transitions, and property behaviors.
The simplest form of animation is a PropertyAnimation, which can animate all of the property types listed above. A property animation can be specified as a value source using the Animation on property syntax. This is especially useful for repeating animations.
The following example creates a bouncing effect:
Usage of QML does not require Qt/C++ knowledge to use, but it can be easily extended via Qt.2526 Any C++ class derived from QObject can be easily registered as a type which can then be instantiated in QML.
QML provides direct access to the following concepts from Qt:
Signal handlers are JavaScript callbacks which allow imperative actions to be taken in response to an event. For instance, the MouseArea element has signal handlers to handle mouse press, release and click:
All signal handler names begin with "on".
Because QML and JavaScript are very similar, almost all code editors supporting JavaScript will work. However full support for syntax highlighting, code completion, integrated help, and a WYSIWYG editor are available in the free cross-platform IDE Qt Creator since version 2.1 and many other IDEs.
The qml executable can be used to run a QML file as a script. If the QML file begins with a shebang it can be made directly executable. However packaging an application for deployment (especially on mobile platforms) generally involves writing a simple C++ launcher and packaging the needed QML files as resources.
"Qt Quick Tutorial". August 7, 2020. Retrieved March 9, 2025. https://wiki.qt.io/Qt_Quick_Tutorial ↩
"Qt 3D Overview: Qt 3D 5.13.1". doc.qt.io. https://doc.qt.io/qt-5/qt3d-overview.html ↩
"All QML Types: Qt 5.13". doc.qt.io. Retrieved September 7, 2019. https://doc.qt.io/qt-5/qmltypes.html ↩
Knoll, Lars (2013-04-15). "Evolution of the QML engine, part 1". Retrieved 2018-05-11. http://blog.qt.io/blog/2013/04/15/evolution-of-the-qml-engine-part-1/ ↩
"What's New in Qt 5.2". Retrieved 2018-05-11. http://doc.qt.io/qt-5/whatsnew52.html ↩
"Qt Quick Compiler". Retrieved September 7, 2019. http://doc.qt.io/QtQuickCompiler/ ↩
"Deploying QML Applications: Qt 5.13". doc.qt.io. Retrieved September 7, 2019. https://doc.qt.io/qt-5/qtquick-deployment.html#qml-caching ↩
"Development/Tutorials/Plasma4/QML/GettingStarted". KDE TechBase. KDE. https://techbase.kde.org/Development/Tutorials/Plasma4/QML/GettingStarted ↩
Dragly, Svenn-Arne (December 2017). "Developing for the reMarkable tablet". dragly. https://dragly.org/2017/12/01/developing-for-the-remarkable/ ↩
"QML Demo for the reMarkable Paper Tablet". GitHub. 9 March 2022. https://github.com/reHackable/reHackable-HelloWorld ↩
"Ubuntu's Unity Written In Qt/QML For "Unity Next"". Michael Larabel. https://www.phoronix.com/scan.php?page=news_item&px=MTMxNzM ↩
"Combining C++ with QML in Sailfish OS applications". https://sailfishos.org/develop/tutorials/combining-c-with-qml/ ↩
"Tutorial - QML Live Coding With Qt QmlLive". https://sailfishos.org/wiki/Tutorial_-_QML_Live_Coding_With_Qt_QmlLive ↩
"QML to C++ and C++ to QML". Jolla. https://together.jolla.com/question/86050/qml-to-c-and-c-to-qml/ ↩
"QML fundamentals". Blackberry. http://developer.blackberry.com/native/documentation/dev/qml_fundamentals/ ↩
"Intro to QML for Meego". Nokia. Archived from the original on 2018-01-04. Retrieved 2018-01-03. https://web.archive.org/web/20180104015312/https://slidedocument.com/intro-to-qml-meego ↩
"MeeGo and Qt–QML demos assault MWC". IoT Gadgets. 23 February 2011. https://www.iotgadgets.com/2011/02/meego-qt-qml-demo-assaults-mwc-nokia-intel/ ↩
"QML on N900". maemo.org. Maemo Community. http://wiki.maemo.org/QML ↩
"Qt Launches on Tizen with Standard Look and Feel". 20 May 2013. http://qtfortizen.blogspot.no/2013/05/1.0alpha1.html ↩
"Mer". http://www.merproject.org/ ↩
"Mer wiki". https://wiki.merproject.org/wiki/Main_Page ↩
"Lipstick QML UI on MeeGo CE / Mer". IoT Gadgets. 6 October 2011. https://www.iotgadgets.com/2011/10/lipstick-qml-ui-meego-ce-mer/ ↩
"QML - the best tool to unlock your creativity". Ubuntu. https://docs.ubuntu.com/phone/en/apps/qml/ ↩
"Looking at Lumina Desktop 2.0". TrueOS. 19 August 2020. https://www.trueos.org/blog/looking-lumina-desktop-2-0/ ↩
Alpert, Alan. "The Qt/QML User Story". Incorrigible Imaginings. https://imaginitis.net/the-qtqml-user-story-redux/ ↩
Alpert, Alan. "The many ways to unite QML and C++". Qt Developer Days. BlackBerry. https://www.qtdeveloperdays.com/north-america/many-ways-unite-qml-and-c.html ↩
Dahlbom, J (22 April 2010). "QAbstractItemModels in QML views". The missing pieces. https://jdahlbom.wordpress.com/2010/04/22/qabstractitemmodels-in-qml-views/ ↩
"Sorting and filtering a TableView". The Qt Company. https://blog.qt.io/blog/2014/04/16/qt-weekly-6-sorting-and-filtering-a-tableview/ ↩
Brad, van der Laan (11 July 2014). "How to use Qt's QSortFilterProxyModel". ImaginativeThinking. http://imaginativethinking.ca/use-qt-qsortfilterproxymodel/ ↩