SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Best Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part IBest Practices in Qt Quick/QML - Part I
Best Practices in Qt Quick/QML - Part I
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
Lessons Learned from Building 100+ C++/Qt/QML Devices
Lessons Learned from Building 100+ C++/Qt/QML DevicesLessons Learned from Building 100+ C++/Qt/QML Devices
Lessons Learned from Building 100+ C++/Qt/QML Devices
 
Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key concepts
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of Qt
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IV
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3
 
Introduction to Qt
Introduction to QtIntroduction to Qt
Introduction to Qt
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 
Qt programming-using-cpp
Qt programming-using-cppQt programming-using-cpp
Qt programming-using-cpp
 
Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4
 
UI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QMLUI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QML
 
Qt Application Programming with C++ - Part 1
Qt Application Programming with C++ - Part 1Qt Application Programming with C++ - Part 1
Qt Application Programming with C++ - Part 1
 
Basics of Model/View Qt programming
Basics of Model/View Qt programmingBasics of Model/View Qt programming
Basics of Model/View Qt programming
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
 
Qt Internationalization
Qt InternationalizationQt Internationalization
Qt Internationalization
 
Qt for beginners
Qt for beginnersQt for beginners
Qt for beginners
 
Introduction to Qt programming
Introduction to Qt programmingIntroduction to Qt programming
Introduction to Qt programming
 

Ähnlich wie Introduction to QML

Qt everywhere a c++ abstraction platform
Qt everywhere   a c++ abstraction platformQt everywhere   a c++ abstraction platform
Qt everywhere a c++ abstraction platform
Develer S.r.l.
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
Johan Thelin
 

Ähnlich wie Introduction to QML (20)

Witekio custom modern qt quick components
Witekio custom modern qt quick componentsWitekio custom modern qt quick components
Witekio custom modern qt quick components
 
Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2
 
Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++
 
Scripting Your Qt Application
Scripting Your Qt ApplicationScripting Your Qt Application
Scripting Your Qt Application
 
CITi - PySide
CITi - PySideCITi - PySide
CITi - PySide
 
Fun with QML
Fun with QMLFun with QML
Fun with QML
 
The Ring programming language version 1.6 book - Part 176 of 189
The Ring programming language version 1.6 book - Part 176 of 189The Ring programming language version 1.6 book - Part 176 of 189
The Ring programming language version 1.6 book - Part 176 of 189
 
The Ring programming language version 1.10 book - Part 104 of 212
The Ring programming language version 1.10 book - Part 104 of 212The Ring programming language version 1.10 book - Part 104 of 212
The Ring programming language version 1.10 book - Part 104 of 212
 
Copy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with QtCopy Your Favourite Nokia App with Qt
Copy Your Favourite Nokia App with Qt
 
Treinamento Qt básico - aula II
Treinamento Qt básico - aula IITreinamento Qt básico - aula II
Treinamento Qt básico - aula II
 
The Ring programming language version 1.9 book - Part 114 of 210
The Ring programming language version 1.9 book - Part 114 of 210The Ring programming language version 1.9 book - Part 114 of 210
The Ring programming language version 1.9 book - Part 114 of 210
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt Data
 
Qt everywhere a c++ abstraction platform
Qt everywhere   a c++ abstraction platformQt everywhere   a c++ abstraction platform
Qt everywhere a c++ abstraction platform
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
 
Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1Petri Niemi Qt Advanced Part 1
Petri Niemi Qt Advanced Part 1
 
Advanced Visualization with OpenGL in Oil & Gas
Advanced Visualization with OpenGL in Oil & GasAdvanced Visualization with OpenGL in Oil & Gas
Advanced Visualization with OpenGL in Oil & Gas
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
 
Building the QML Run-time
Building the QML Run-timeBuilding the QML Run-time
Building the QML Run-time
 
Return of c++
Return of c++Return of c++
Return of c++
 

Kürzlich hochgeladen

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Kürzlich hochgeladen (20)

WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

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