SlideShare a Scribd company logo
3
Most read
11
Most read
12
Most read
Introduction to QML
by Alan Uthoff
History
• Started by Haavard Nord and Erik Chambe-Eng in 1991
• Founded Trolltech three years later
• Acquired by Nokia in 2008
• QML is created for mobile development (n900 and N1)
• Sold to Digia in 2011
• Transfered to QT Company
• Current version of QT is 5.9
QML
• Declarative JavaScript language with built in
hooks for Cpp
• All signal, slots and properties on a c++ class
are automatically exposed to QML
• Can expose C++ method with Q_INVOKABLE
• Prototype inheritance
Basic Types
QML C++
string QString
int int
bool bool
double double
real float
url QUrl
var QVariant
list QList
Object Attributes
Rectangle {
id: myRect
property int foo: 1
signal mysignal
Rectangel {
height: myRect
}
Component.onComplete: {
myRect.foo = 3
}
}
Object Types
• Component
• Item
• Rectangle
• Row
• Column
• Repeter
• Etc…
Row
• Layout objects in a row
import QtQuick 2.0
Row {
spacing: 2
Rectangle { color: "red"; width: 50; height: 50 }
Rectangle { color: "green"; width: 20; height: 50 }
Rectangle { color: "blue"; width: 50; height: 20 }
}
Column
• Layout objects in a column
Column {
spacing: 2
Rectangle { color: "red"; width: 50; height: 50 }
Rectangle { color: "green"; width: 20; height: 50 }
Rectangle { color: "blue"; width: 50; height: 20 }
}
Repeater
• Repeats an object n number of times
import QtQuick 2.0
Row {
Repeater {
model: 3
Rectangle {
width: 100; height: 40
border.width: 1
color: "yellow"
}
}
}
Signal And Slots
• QML Supports signals to slots
• QML to QML
• QML to C++
• C++ to QML
Signal QML Example
Item {
Rectangle {
id: myRect
width: 100
signal click(string value)
}
Rectangle {
width: (myRect.width <200) ? myRect.width :200
MouseArea:
{
onClicked:
{
if(mouse == Qt.LeftButton)
{
myRect.click(“Left)
}
}
}
}
}
QML To C++
QList<QObject *> objList = engine.rootObjects();
QObject *qmlObject = nullptr;
qmlObject = objList[0];//assumes the top object has the
signal
QObject::connect(qmlObject, SIGNAL(click(QString)),
&cppObjWithSlot,
SLOT(processClick(QString)));
Exposing C++ to QML
• Signal and Slots
• Methods with Q_INVOKABLE
• Properties Q_PROPERTY
Assume the C++
class MessageBoard : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE bool postMessage(const QString &msg) ;
Q_PROPERTY(MessageBody* body READ body WRITE setBody NOTIFY bodyChanged)
signals:
void newMessagePosted(const QString &subject);
public slots:
void refresh();
};
int main(int argc, char *argv[]) {
MessageBoard msgBoard;
QQuickView view;
view.engine()->rootContext()->setContextProperty("msgBoard", &msgBoard);
view.setSource(QUrl::fromLocalFile("MyItem.qml"));
}
QML Calling C++
// MyItem.qml
import QtQuick 2.0
Item {
MouseArea {
anchors.fill: parent
onClicked: {
var result = msgBoard.postMessage("Hello from QML")
msgBoard.refresh();
}
MessageBoard {
body: MessageBody {
}
onNewMessagePosted: console.log("New message received:", subject)
}
}
}
Javascript in QML
• Can be in a binding
• Standalone function
• Imported from a .js file
Javascript Example
Item {
Rectangle {
id: myRect
width: 100
function click()
{
}
Rectangle {
width: (myRect.width <200) ? myRect.width :200
MouseArea:
{
onClicked:
{
myRect.click()
}
}
}
}
Javascript From File
//in file myJavascipt.js
function click {
}
//Qml
import QtQuick 2.0
import myJavascript.js as myJavascript
Rectangle
{
Component.OnComplete
{
myJavascrtipt.click()
}
}
GUI Systems
• Make your own with Rectangle
• QT Controls 1.0
• QT Controls 2.0
Layout Systems
• Row Column
• Bindings (set them your self)
• Anchors
• Layout
Models
• QML has build in model (ListModel)
• Can create custom models from C++
Render Backends
• Qml is a scene graph
• Directx 12
• OpenGL
• Software
QML Help
• QML book
• https://qmlbook.github.io
• QML Docs
• http://doc.qt.io/qt-5/qtqml-index.html

More Related Content

PDF
U-Boot - An universal bootloader
PDF
Embedded Android : System Development - Part I
PDF
Python programming : Standard Input and Output
PPTX
Robot operating system [ROS]
PPTX
Database security
PPTX
Diabetes Mellitus
PPTX
Hypertension
U-Boot - An universal bootloader
Embedded Android : System Development - Part I
Python programming : Standard Input and Output
Robot operating system [ROS]
Database security
Diabetes Mellitus
Hypertension

What's hot (20)

PPTX
Qt Qml
PPTX
Hello, QML
PDF
In-Depth Model/View with QML
 
PDF
Best Practices in Qt Quick/QML - Part 1 of 4
 
PDF
Best Practices in Qt Quick/QML - Part II
 
PDF
02 - Basics of Qt
PDF
Qt multi threads
PPTX
Best Practices in Qt Quick/QML - Part I
 
ODP
Qt 5 - C++ and Widgets
PPTX
Qt for beginners part 1 overview and key concepts
 
PPTX
UI Programming with Qt-Quick and QML
PDF
Qt Application Programming with C++ - Part 1
PDF
QThreads: Are You Using Them Wrong?
 
PDF
Lessons Learned from Building 100+ C++/Qt/QML Devices
 
PDF
Best Practices in Qt Quick/QML - Part IV
 
PDF
QVariant, QObject — Qt's not just for GUI development
 
PDF
Basics of Model/View Qt programming
 
PPTX
Qt Framework Events Signals Threads
PDF
Qt Application Programming with C++ - Part 2
ODP
Qt Workshop
Qt Qml
Hello, QML
In-Depth Model/View with QML
 
Best Practices in Qt Quick/QML - Part 1 of 4
 
Best Practices in Qt Quick/QML - Part II
 
02 - Basics of Qt
Qt multi threads
Best Practices in Qt Quick/QML - Part I
 
Qt 5 - C++ and Widgets
Qt for beginners part 1 overview and key concepts
 
UI Programming with Qt-Quick and QML
Qt Application Programming with C++ - Part 1
QThreads: Are You Using Them Wrong?
 
Lessons Learned from Building 100+ C++/Qt/QML Devices
 
Best Practices in Qt Quick/QML - Part IV
 
QVariant, QObject — Qt's not just for GUI development
 
Basics of Model/View Qt programming
 
Qt Framework Events Signals Threads
Qt Application Programming with C++ - Part 2
Qt Workshop
Ad

Similar to Introduction to QML (20)

PDF
Best Practices in Qt Quick/QML - Part III
 
PPTX
Witekio custom modern qt quick components
PDF
Integrazione QML / C++
PDF
Scripting Your Qt Application
PDF
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
PDF
CITi - PySide
PDF
Best Practices in Qt Quick/QML - Part 3
 
PDF
Qt for beginners
PDF
Fun with QML
 
PDF
The Ring programming language version 1.6 book - Part 176 of 189
PDF
The Ring programming language version 1.10 book - Part 104 of 212
PDF
Copy Your Favourite Nokia App with Qt
ODP
Treinamento Qt básico - aula II
PDF
The Ring programming language version 1.9 book - Part 114 of 210
PDF
04 - Qt Data
PDF
Qt everywhere a c++ abstraction platform
PDF
Petri Niemi Qt Advanced Part 2
PDF
Petri Niemi Qt Advanced Part 1
PDF
Advanced Visualization with OpenGL in Oil & Gas
PPTX
PVS-Studio team experience: checking various open source projects, or mistake...
Best Practices in Qt Quick/QML - Part III
 
Witekio custom modern qt quick components
Integrazione QML / C++
Scripting Your Qt Application
“ONNX and Python to C++: State-of-the-art Graph Compilation,” a Presentation ...
CITi - PySide
Best Practices in Qt Quick/QML - Part 3
 
Qt for beginners
Fun with QML
 
The Ring programming language version 1.6 book - Part 176 of 189
The Ring programming language version 1.10 book - Part 104 of 212
Copy Your Favourite Nokia App with Qt
Treinamento Qt básico - aula II
The Ring programming language version 1.9 book - Part 114 of 210
04 - Qt Data
Qt everywhere a c++ abstraction platform
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 1
Advanced Visualization with OpenGL in Oil & Gas
PVS-Studio team experience: checking various open source projects, or mistake...
Ad

Recently uploaded (20)

PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
System and Network Administration Chapter 2
PPTX
L1 - Introduction to python Backend.pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Introduction to Artificial Intelligence
How to Choose the Right IT Partner for Your Business in Malaysia
Odoo POS Development Services by CandidRoot Solutions
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Which alternative to Crystal Reports is best for small or large businesses.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PTS Company Brochure 2025 (1).pdf.......
System and Network Administration Chapter 2
L1 - Introduction to python Backend.pptx
top salesforce developer skills in 2025.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
How Creative Agencies Leverage Project Management Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Introduction to Artificial Intelligence

Introduction to QML

  • 2. History • Started by Haavard Nord and Erik Chambe-Eng in 1991 • Founded Trolltech three years later • Acquired by Nokia in 2008 • QML is created for mobile development (n900 and N1) • Sold to Digia in 2011 • Transfered to QT Company • Current version of QT is 5.9
  • 3. QML • Declarative JavaScript language with built in hooks for Cpp • All signal, slots and properties on a c++ class are automatically exposed to QML • Can expose C++ method with Q_INVOKABLE • Prototype inheritance
  • 4. Basic Types QML C++ string QString int int bool bool double double real float url QUrl var QVariant list QList
  • 5. Object Attributes Rectangle { id: myRect property int foo: 1 signal mysignal Rectangel { height: myRect } Component.onComplete: { myRect.foo = 3 } }
  • 6. Object Types • Component • Item • Rectangle • Row • Column • Repeter • Etc…
  • 7. Row • Layout objects in a row import QtQuick 2.0 Row { spacing: 2 Rectangle { color: "red"; width: 50; height: 50 } Rectangle { color: "green"; width: 20; height: 50 } Rectangle { color: "blue"; width: 50; height: 20 } }
  • 8. Column • Layout objects in a column Column { spacing: 2 Rectangle { color: "red"; width: 50; height: 50 } Rectangle { color: "green"; width: 20; height: 50 } Rectangle { color: "blue"; width: 50; height: 20 } }
  • 9. Repeater • Repeats an object n number of times import QtQuick 2.0 Row { Repeater { model: 3 Rectangle { width: 100; height: 40 border.width: 1 color: "yellow" } } }
  • 10. Signal And Slots • QML Supports signals to slots • QML to QML • QML to C++ • C++ to QML
  • 11. Signal QML Example Item { Rectangle { id: myRect width: 100 signal click(string value) } Rectangle { width: (myRect.width <200) ? myRect.width :200 MouseArea: { onClicked: { if(mouse == Qt.LeftButton) { myRect.click(“Left) } } } } }
  • 12. QML To C++ QList<QObject *> objList = engine.rootObjects(); QObject *qmlObject = nullptr; qmlObject = objList[0];//assumes the top object has the signal QObject::connect(qmlObject, SIGNAL(click(QString)), &cppObjWithSlot, SLOT(processClick(QString)));
  • 13. Exposing C++ to QML • Signal and Slots • Methods with Q_INVOKABLE • Properties Q_PROPERTY
  • 14. Assume the C++ class MessageBoard : public QObject { Q_OBJECT public: Q_INVOKABLE bool postMessage(const QString &msg) ; Q_PROPERTY(MessageBody* body READ body WRITE setBody NOTIFY bodyChanged) signals: void newMessagePosted(const QString &subject); public slots: void refresh(); }; int main(int argc, char *argv[]) { MessageBoard msgBoard; QQuickView view; view.engine()->rootContext()->setContextProperty("msgBoard", &msgBoard); view.setSource(QUrl::fromLocalFile("MyItem.qml")); }
  • 15. QML Calling C++ // MyItem.qml import QtQuick 2.0 Item { MouseArea { anchors.fill: parent onClicked: { var result = msgBoard.postMessage("Hello from QML") msgBoard.refresh(); } MessageBoard { body: MessageBody { } onNewMessagePosted: console.log("New message received:", subject) } } }
  • 16. Javascript in QML • Can be in a binding • Standalone function • Imported from a .js file
  • 17. Javascript Example Item { Rectangle { id: myRect width: 100 function click() { } Rectangle { width: (myRect.width <200) ? myRect.width :200 MouseArea: { onClicked: { myRect.click() } } } }
  • 18. Javascript From File //in file myJavascipt.js function click { } //Qml import QtQuick 2.0 import myJavascript.js as myJavascript Rectangle { Component.OnComplete { myJavascrtipt.click() } }
  • 19. GUI Systems • Make your own with Rectangle • QT Controls 1.0 • QT Controls 2.0
  • 20. Layout Systems • Row Column • Bindings (set them your self) • Anchors • Layout
  • 21. Models • QML has build in model (ListModel) • Can create custom models from C++
  • 22. Render Backends • Qml is a scene graph • Directx 12 • OpenGL • Software
  • 23. QML Help • QML book • https://qmlbook.github.io • QML Docs • http://doc.qt.io/qt-5/qtqml-index.html