HOME

TheInfoList



OR:

QML (Qt Modeling Language) is a
user interface markup language A user interface markup language is a markup language that renders and describes graphical user interfaces and controls. Many of these markup languages are dialects of XML and are dependent upon a pre-existing scripting language engine, usually ...
. It is a declarative language (similar to
CSS Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation of a document written in a markup language such as HTML or XML (including XML dialects such as SVG, MathML or XHTML). CSS is a cornerstone technolo ...
and
JSON JSON (JavaScript Object Notation, pronounced ; also ) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other se ...
) for designing user interface–centric applications. Inline
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
code handles imperative aspects. It is associated with Qt Quick, the UI creation kit originally developed by
Nokia Nokia Corporation (natively Nokia Oyj, referred to as Nokia) is a Finnish multinational telecommunications, information technology, and consumer electronics corporation, established in 1865. Nokia's main headquarters are in Espoo, Finland, i ...
within the Qt framework. Qt Quick is used for mobile applications where touch input, fluid animations and user experience are crucial. QML is also used with Qt3D to describe a 3D scene and a "frame graph" rendering methodology. A QML document describes a hierarchical object tree. QML modules shipped with Qt include primitive graphical building blocks (e.g., Rectangle, Image), modeling components (e.g., FolderListModel, XmlListModel), behavioral components (e.g., TapHandler, DragHandler, State, Transition, Animation), and more complex controls (e.g., Button, Slider, Drawer, Menu). These elements can be combined to build components ranging in complexity from simple buttons and sliders, to complete internet-enabled programs. QML elements can be augmented by standard
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
both inline and via included .js files. Elements can also be seamlessly integrated and extended by
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
components using the Qt framework. QML is the language; its JavaScript runtime is the custom V4 engine, since Qt 5.2; and Qt Quick is the 2D
scene graph Scene (from Greek σκηνή ''skēnḗ'') may refer to: Arts, entertainment, and media Music * Scene (subculture), a youth subculture from the early 2000s characterized by a distinct music and style. Groups and performers * The Scene who rec ...
and the UI framework based on it. These are all part of the Qt Declarative module, while the technology is no longer called Qt Declarative. QML and JavaScript code can be compiled into native C++ binaries with the Qt Quick Compiler. Alternatively there is a QML cache file format which stores a compiled version of QML dynamically for faster startup the next time it is run.


Adoption

*
KDE Plasma 4 KDE Plasma 4 was the fourth generation of the KDE workspace environments. It consisted of three workspaces, each targeting a certain platform: ''Plasma Desktop'' for traditional desktop PCs and notebooks, ''Plasma Netbook'' for netbooks, and ''Pl ...
and
KDE Plasma 5 KDE Plasma 5 is the fifth and current generation of the graphical workspaces environment created by KDE primarily for Linux systems. KDE Plasma 5 is the successor of KDE Plasma 4 and was first released on 15 July 2014. It includes a new default ...
through
Plasma-framework KDE Frameworks is a collection of libraries and software frameworks readily available to any Qt-based software stacks or applications on multiple operating systems. Featuring frequently needed functionality solutions like hardware integration, fi ...

Liri OS
*
Simple Desktop Display Manager Simple Desktop Display Manager (SDDM) is a display manager (a graphical login program and session manager) for the X11 and Wayland windowing systems. SDDM was written from scratch in C++11 and supports theming via QML. SDDM is free and open- ...

reMarkable tablet device
* Unity2D *
Sailfish OS Sailfish OS is a Linux-based operating system based on free software, and open source projects such as Mer as well as including a closed source UI. The project is being developed by the Finnish company Jolla. The OS first shipped with the ...
*
BlackBerry 10 BlackBerry 10 is a discontinued proprietary mobile operating system for the BlackBerry line of smartphones, both developed by BlackBerry Limited (formerly Research In Motion). BlackBerry 10 is based on QNX, a Unix-like operating system that was ...
*
MeeGo MeeGo is a discontinued Linux distribution hosted by the Linux Foundation, using source code from the operating systems Moblin (produced by Intel) and Maemo (produced by Nokia). Primarily targeted at mobile devices and information appliances ...
*
Maemo Maemo is a software platform originally developed by Nokia, now developed by the community, for smartphones and Internet tablets. The platform comprises both the Maemo operating system and SDK. Maemo played a key role in Nokia's strategy to c ...
*
Tizen Tizen () is a Linux-based mobile operating system backed by the Linux Foundation, mainly developed and used primarily by Samsung Electronics. The project was originally conceived as an HTML5-based platform for mobile devices to succeed MeeGo. ...
* Mer *
Ubuntu Phone Ubuntu Touch is a mobile version of the Ubuntu operating system, being developed by the UBports community. Its user interface is written in Qt, and is designed primarily for touchscreen mobile devices such as smartphones and tablet computers, ...
* Lumina (desktop environment) * Man
open-source applications


Syntax, semantics


Basic syntax

Example: import QtQuick Rectangle 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, we can see 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. Item Note that an id must begin with a lower-case letter or an underscore, and cannot contain characters other than letters, digits and underscores.


Property bindings

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 In computing, reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change. With this paradigm, it's possible to express static (e.g., arrays) or dynamic (e.g., event emitters) data streams ...
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. Rectangle 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. Example: Rectangle


States

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. import QtQuick Item State changes can be animated using Transitions. For example, adding this code to the above Item element animates the transition to the "moved" state: transitions: Transition


Animation

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: Rectangle


Qt/C++ integration

Usage of QML does not require Qt/C++ knowledge to use, but it can be easily extended via Qt. Any C++ class derived from QObject can be easily registered as a type which can then be instantiated in QML.


Familiar concepts

QML provides direct access to the following concepts from Qt: * QObject signals – can trigger callbacks in JavaScript * QObject slots – available as functions to call in JavaScript * QObject properties – available as variables in JavaScript, and for bindings * QWindow – Window creates a QML scene in a window * Q*Model – used directly in data binding (e.g. QAbstractItemModel)


Signal handlers

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: MouseArea All signal handler names begin with "on".


Development tools

Because QML and JavaScript are very similar, almost all code editors supporting JavaScript will work. However full support for
syntax highlighting Syntax highlighting is a feature of text editors that are used for programming, scripting, or markup languages, such as HTML. The feature displays text, especially source code, in different colours and fonts according to the category of terms ...
, code completion, integrated help, and a WYSIWYG editor are available in the free cross-platform IDE
Qt Creator Qt Creator is a cross-platform C++, JavaScript and QML integrated development environment (IDE) which simplifies GUI application development. It is part of the SDK for the Qt GUI application development framework and uses the Qt API, which e ...
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 necessary QML files as resources.


References


External links


QML Reference Documentation





Qt Blog



Qt Developer Guides

Exporting QML from Photoshop and GIMP

Application complete invoicing system in QML - Khitomer

QML Book


How-tos





{{Qt Declarative programming languages Qt (software) User interface markup languages