HOME

TheInfoList



OR:

QML (Qt Meta-object Language) is a user interface markup language. It is a declarative language (similar to CSS and
JSON JSON (JavaScript Object Notation, pronounced or ) is an open standard file format and electronic data interchange, data interchange format that uses Human-readable medium and data, human-readable text to store and transmit data objects consi ...
) for designing
user interface In the industrial design field of human–computer interaction, a user interface (UI) is the space where interactions between humans and machines occur. The goal of this interaction is to allow effective operation and control of the machine fro ...
–centric applications. Inline
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
code handles imperative aspects. It is associated with Qt Quick, the UI creation kit originally developed by
Nokia Nokia Corporation is a Finnish multinational corporation, multinational telecommunications industry, telecommunications, technology company, information technology, and consumer electronics corporation, originally established as a pulp mill in 1 ...
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 and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
both inline and via included .js files. Elements can also be seamlessly integrated and extended by C++ 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 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 is the fourth generation of the KDE workspace environments. It consists of three workspaces, each targeting a certain platform: ''Plasma Desktop'' for traditional desktop PCs and Notebook (computer), notebooks, ''Plasma Netbook'' for ...
, KDE Plasma 5 and Plasma 6 through Plasma-framework
Liri OS
* Simple Desktop Display Manager
reMarkable tablet device
* Unity2D * Sailfish OS * BlackBerry 10 * MeeGo * Maemo * Tizen * Mer * Ubuntu Phone * Lumina (desktop environment) * Man
open-source applications


Syntax, semantics

Some
syntax In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
examples follow:


Basic syntax

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, 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 An id must begin with a lower-case letter or an underscore, and can contain no 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 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. 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. Full support for syntax highlighting, code completion, integrated help, and a WYSIWYG editor are available in the free cross-platform
integrated development environment An integrated development environment (IDE) is a Application software, software application that provides comprehensive facilities for software development. An IDE normally consists of at least a source-code editor, build automation tools, an ...
(IDE)
Qt Creator Qt Creator is a cross-platform C++, JavaScript, Python 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 Q ...
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.


References


External links


QML Reference Documentation





Qt Blog



Qt Developer Guides

Exporting QML from Photoshop and GIMP

QML Book


How-tos





{{Qt platform Declarative programming languages Qt (software) User interface markup languages Articles with example JavaScript code