SlideShare a Scribd company logo
1 of 24
Download to read offline
Qt Quick in Depth




Lorenzo Mancini (lmancini@develer.com)
Qt Quick: a case study
   Remake of Vodafone's TVConnect UI
   Developed to demonstrate QQ's:
          Conciseness
          Performance
          Overall toolchain
Qt Creator configuration
   New Qt Quick Application
   Integrate with Mercurial
   Test the Application Viewer
   Create a new run configuration
          Projects->Run
          qmlviewer %{CurrentDocument:FilePath}
          We'll use this to test single pages
Qt Creator configuration
   Enable QML debugging
          Projects->Build
          Build Steps->Link QML debugging library
          (Rebuild all)
   You only have to do all this once
          This is all saved in .pro.user file
The Home menu
   Background image
   No states
   Series of icons following a path
QML Views
   List visualization for models
   Models provide homogeneous data
   Each data is represented by delegates
   Interesting properties:
          model
          highlight
          delegate
ListView
   Standard QML View
          Lays delegates in a list
   A ListView in practice
          Place it on view
          Add a Model
          Define a Delegate
                  E.g. Component / Column / Image + Text
Model


ListModel {
    id: path_model
    ListElement {
        name: "TV"
        icon: "res/main_menu/tv_selected.png"
    }
    ListElement {
        name: "Audio"
        icon: "res/main_menu/audio_selected.png"
    }
    // ...
}
Delegate
Component {
    id: path_delegate
    Column {
        id: wrapper
        Image {
            source: icon
            width: list_view1.width / 5
            fillMode: Image.PreserveAspectFit
        }
        Text {
            text: name
            anchors.horizontalCenter: parent.horizontalCenter
            font.pointSize: 24
            color: "#77FFFFFF"
        }
    }
}
Bind to view


ListView {
        // ...

       orientation: ListView.Horizontal
       model: path_model
       delegate: path_delegate
}
PathView
   Standard QML View
          Defines a path that items follow
   A PathView in practice
          Place it on view
          Add a Model
          Define a Delegate
          Define a Path
Path Definition

PathView {
    // ...

    focus: true
    model: path_model
    delegate: path_delegate

    Keys.onLeftPressed: decrementCurrentIndex()
    Keys.onRightPressed: incrementCurrentIndex()

    path: Path {
        startX: 0
        startY: path_view1.height / 2
        PathLine { x: path_view1.width; y: path_view1.height / 2}
    }
}
A more interesting path
Component {
    id: path_delegate
    //...
    Column {
        opacity: PathView.iconOpacity
    }
}
    path: Path {
        startX: 0
        startY: path_view1.height / 2
        PathAttribute { name: "iconOpacity"; value: 0.5 }

       PathLine { x: path_view1.width / 2; y: path_view1.height / 2}
       PathAttribute { name: "iconOpacity"; value: 1.0 }

       PathLine { x: path_view1.width; y: path_view1.height / 2}
       PathAttribute { name: "iconOpacity"; value: 0.5 }
   }
QML in C++ applications
   Use QDeclarativeView to embed QML
          QGraphicsView subclass, QWidget's as well
   Useful to add QML features on top of
    already existing applications
   Keep an eye on startup time and memory
    usage




                                                       14
QML in C++ applications
   QML functions can be called via
    QMetaObject::invokeMethod()
   QML objects can emit signals that C++
    code can QObject::connect()
   → you can define an interface for QML
    objects
   C++ properties / signals / slots are
    exposed to QML via the Meta Object
    System
                                            15
QML Models in C++
   QML doesn't have direct access to
    hardware
   What if we want to retrieve a list of
    channel from a TV tuner?
   We can subclass QAbstractItemModel,
    implement the desired model in C++ and
    use it from QML.



                                            16
The TV menu
   Two states:
          TV only
          overlay on screen
   A channel list (reusable component)
   A C++ model to retrieve channels




                                          17
Putting it all together
   Fast forward: we have several QML files,
    one for each page
   We would like to “instantiate” and load a
    QML file on-the-fly




                                                18
Dynamic Object Management
   Dynamic object creation from Javascript
   Qt.createComponent(url) → Component
   Component.createObject(parent) → inst
   The QML file can be fetched over the
    network
          Great for implementing live widgets!
          … but the fetch is asynchronous: how do I know
            when it's finished?


                                                            19
Dynamic Object Management
 function createObject() {
     component = Qt.createComponent("Sprite.qml");
     if (component.status == Component.Ready)
          finishCreation();
     else
          component.statusChanged.connect(finishCreation);
 }

function finishCreation() {
     if (component.status == Component.Ready) {
         sprite = component.createObject(appWindow);
         // …
     }
}




                                                             20
A stack of pages
   In most STBs, pages are in a stack
          Entering a page → push
          Previous page → pop
          Panic button (home menu) → clear
   We need a persistent global state for this




                                                 21
Stack implementation
// Stack.js
var stack = []
// Create a QML object from a given filename and push it on the stack
function openPage(filename) {
    var page_c = Qt.createComponent(filename)
    var page = page_c.createObject(root_window)
    stack.push(page)
    return page
}



// Page.qml
Import “stack.js” as Stack

Page {
    Keys.onReturnPressed: {
        Stack.openPage(“tvmenu.qml”)
    }
}



                                                                        22
Stack implementation
   Sounds great! ...But alas, it doesn't work
          A new execution context is created for the use of
             the importing Component only
   QML JS can't modify global object
    members either
   .pragma library
          Placed at the top of a JS module, tells QML that
             this module is stateless, so it's instance can
             freely shared
          Handle with care
                                                              23
THANKS !
                                Develer S.r.l.
                             Via Mugellese 1/A
                         50013 Campi Bisenzio
                                 Firenze - Italy




Contacts
Mail: info@develer.com
Phone: +39-055-3984627
Fax: +39 178 6003614
http://www.develer.com

More Related Content

What's hot

Clockless design language - ilia greenblat
Clockless design language - ilia greenblatClockless design language - ilia greenblat
Clockless design language - ilia greenblat
chiportal
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 
Simple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time JavaSimple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time Java
Universidad Carlos III de Madrid
 

What's hot (20)

QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
2011.jtr.pbasanta.
2011.jtr.pbasanta.2011.jtr.pbasanta.
2011.jtr.pbasanta.
 
Building the QML Run-time
Building the QML Run-timeBuilding the QML Run-time
Building the QML Run-time
 
No Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time JavaNo Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time Java
 
Qt for S60
Qt for S60Qt for S60
Qt for S60
 
Clockless design language - ilia greenblat
Clockless design language - ilia greenblatClockless design language - ilia greenblat
Clockless design language - ilia greenblat
 
Enhancing the region model of RTSJ
Enhancing the region model of RTSJEnhancing the region model of RTSJ
Enhancing the region model of RTSJ
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)Reactive Qt - Ivan Čukić (Qt World Summit 2015)
Reactive Qt - Ivan Čukić (Qt World Summit 2015)
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
 
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
 
NvFX GTC 2013
NvFX GTC 2013NvFX GTC 2013
NvFX GTC 2013
 
S emb t13-freertos
S emb t13-freertosS emb t13-freertos
S emb t13-freertos
 
Simple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time JavaSimple asynchronous remote invocations for distributed real-time Java
Simple asynchronous remote invocations for distributed real-time Java
 
vkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan APIvkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan API
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
NIR on the Mesa i965 backend (FOSDEM 2016)
NIR on the Mesa i965 backend (FOSDEM 2016)NIR on the Mesa i965 backend (FOSDEM 2016)
NIR on the Mesa i965 backend (FOSDEM 2016)
 
State of the Art OpenGL and Qt
State of the Art OpenGL and QtState of the Art OpenGL and Qt
State of the Art OpenGL and Qt
 
Parallel R
Parallel RParallel R
Parallel R
 
Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++
 

Viewers also liked

Viewers also liked (13)

Wprowadzenie do QML
Wprowadzenie do QMLWprowadzenie do QML
Wprowadzenie do QML
 
Test driving-qml
Test driving-qmlTest driving-qml
Test driving-qml
 
QtQuick Day 4
QtQuick Day 4QtQuick Day 4
QtQuick Day 4
 
QtQuick Day 2
QtQuick Day 2QtQuick Day 2
QtQuick Day 2
 
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing more
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
QtQuick Day 1
QtQuick Day 1QtQuick Day 1
QtQuick Day 1
 
qt-project.org and Qt 5
qt-project.org and Qt 5qt-project.org and Qt 5
qt-project.org and Qt 5
 
Qt for beginners part 5 ask the experts
Qt for beginners part 5   ask the expertsQt for beginners part 5   ask the experts
Qt for beginners part 5 ask the experts
 
QML\Qt Quick на практике
QML\Qt Quick на практикеQML\Qt Quick на практике
QML\Qt Quick на практике
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme Change
 

Similar to Qt Quick in depth

Samsung WebCL Prototype API
Samsung WebCL Prototype APISamsung WebCL Prototype API
Samsung WebCL Prototype API
Ryo Jin
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
Benjamin Cabé
 

Similar to Qt Quick in depth (20)

In-Depth Model/View with QML
In-Depth Model/View with QMLIn-Depth Model/View with QML
In-Depth Model/View with QML
 
Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
 
Qt
QtQt
Qt
 
Samsung WebCL Prototype API
Samsung WebCL Prototype APISamsung WebCL Prototype API
Samsung WebCL Prototype API
 
Migrating Objective-C to Swift
Migrating Objective-C to SwiftMigrating Objective-C to Swift
Migrating Objective-C to Swift
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
Qt & Webkit
Qt & WebkitQt & Webkit
Qt & Webkit
 
Gui
GuiGui
Gui
 
The caQtDM powerpoint (ICALEPCS 2013)
The caQtDM powerpoint (ICALEPCS 2013)The caQtDM powerpoint (ICALEPCS 2013)
The caQtDM powerpoint (ICALEPCS 2013)
 
The caQtDm paper (ICALEPCS 2013)
The caQtDm paper (ICALEPCS 2013)The caQtDm paper (ICALEPCS 2013)
The caQtDm paper (ICALEPCS 2013)
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
 
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
 
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfDeveloping and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
 
iOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsiOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI Components
 
WPF - the future of GUI is near
WPF - the future of GUI is nearWPF - the future of GUI is near
WPF - the future of GUI is near
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
Highload JavaScript Framework without Inheritance
Highload JavaScript Framework without InheritanceHighload JavaScript Framework without Inheritance
Highload JavaScript Framework without Inheritance
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface Components
 

More from Develer S.r.l.

Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linuxTrace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Develer S.r.l.
 
Cloud computing, in practice ~ develer workshop
Cloud computing, in practice ~ develer workshopCloud computing, in practice ~ develer workshop
Cloud computing, in practice ~ develer workshop
Develer S.r.l.
 

More from Develer S.r.l. (19)

Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linuxTrace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
Trace32 lo-strumento-piu-completo-per-il-debug-di-un-sistema-linux
 
Sw libero rf
Sw libero rfSw libero rf
Sw libero rf
 
Engagement small
Engagement smallEngagement small
Engagement small
 
Farepipi
FarepipiFarepipi
Farepipi
 
Cloud computing, in practice ~ develer workshop
Cloud computing, in practice ~ develer workshopCloud computing, in practice ~ develer workshop
Cloud computing, in practice ~ develer workshop
 
Workshop su Android Kernel Hacking
Workshop su Android Kernel HackingWorkshop su Android Kernel Hacking
Workshop su Android Kernel Hacking
 
BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011BeRTOS Embedded Survey Summary 2011
BeRTOS Embedded Survey Summary 2011
 
Qt roadmap: the future of Qt
Qt roadmap: the future of QtQt roadmap: the future of Qt
Qt roadmap: the future of Qt
 
Qt Quick for dynamic UI development
Qt Quick for dynamic UI developmentQt Quick for dynamic UI development
Qt Quick for dynamic UI development
 
Qt licensing: making the right choice
Qt licensing: making the right choiceQt licensing: making the right choice
Qt licensing: making the right choice
 
Qt Creator: the secret weapon of any c++ programmer
Qt Creator: the secret weapon of any c++ programmerQt Creator: the secret weapon of any c++ programmer
Qt Creator: the secret weapon of any c++ programmer
 
PyQt: rapid application development
PyQt: rapid application developmentPyQt: rapid application development
PyQt: rapid application development
 
Hybrid development using Qt webkit
Hybrid development using Qt webkitHybrid development using Qt webkit
Hybrid development using Qt webkit
 
Smashing the bottleneck: Qt application profiling
Smashing the bottleneck: Qt application profilingSmashing the bottleneck: Qt application profiling
Smashing the bottleneck: Qt application profiling
 
BeRTOS: Sistema Real Time Embedded Free
BeRTOS: Sistema Real Time Embedded FreeBeRTOS: Sistema Real Time Embedded Free
BeRTOS: Sistema Real Time Embedded Free
 
BeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOSBeRTOS: Free Embedded RTOS
BeRTOS: Free Embedded RTOS
 
Develer - Company Profile
Develer - Company ProfileDeveler - Company Profile
Develer - Company Profile
 
Bettersoftware Feedback 2009
Bettersoftware Feedback 2009Bettersoftware Feedback 2009
Bettersoftware Feedback 2009
 
Develer - Qt Embedded - Introduzione
Develer - Qt Embedded - Introduzione Develer - Qt Embedded - Introduzione
Develer - Qt Embedded - Introduzione
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 

Qt Quick in depth

  • 1. Qt Quick in Depth Lorenzo Mancini (lmancini@develer.com)
  • 2. Qt Quick: a case study  Remake of Vodafone's TVConnect UI  Developed to demonstrate QQ's:  Conciseness  Performance  Overall toolchain
  • 3. Qt Creator configuration  New Qt Quick Application  Integrate with Mercurial  Test the Application Viewer  Create a new run configuration  Projects->Run  qmlviewer %{CurrentDocument:FilePath}  We'll use this to test single pages
  • 4. Qt Creator configuration  Enable QML debugging  Projects->Build  Build Steps->Link QML debugging library  (Rebuild all)  You only have to do all this once  This is all saved in .pro.user file
  • 5. The Home menu  Background image  No states  Series of icons following a path
  • 6. QML Views  List visualization for models  Models provide homogeneous data  Each data is represented by delegates  Interesting properties:  model  highlight  delegate
  • 7. ListView  Standard QML View  Lays delegates in a list  A ListView in practice  Place it on view  Add a Model  Define a Delegate  E.g. Component / Column / Image + Text
  • 8. Model ListModel { id: path_model ListElement { name: "TV" icon: "res/main_menu/tv_selected.png" } ListElement { name: "Audio" icon: "res/main_menu/audio_selected.png" } // ... }
  • 9. Delegate Component { id: path_delegate Column { id: wrapper Image { source: icon width: list_view1.width / 5 fillMode: Image.PreserveAspectFit } Text { text: name anchors.horizontalCenter: parent.horizontalCenter font.pointSize: 24 color: "#77FFFFFF" } } }
  • 10. Bind to view ListView { // ... orientation: ListView.Horizontal model: path_model delegate: path_delegate }
  • 11. PathView  Standard QML View  Defines a path that items follow  A PathView in practice  Place it on view  Add a Model  Define a Delegate  Define a Path
  • 12. Path Definition PathView { // ... focus: true model: path_model delegate: path_delegate Keys.onLeftPressed: decrementCurrentIndex() Keys.onRightPressed: incrementCurrentIndex() path: Path { startX: 0 startY: path_view1.height / 2 PathLine { x: path_view1.width; y: path_view1.height / 2} } }
  • 13. A more interesting path Component { id: path_delegate //... Column { opacity: PathView.iconOpacity } } path: Path { startX: 0 startY: path_view1.height / 2 PathAttribute { name: "iconOpacity"; value: 0.5 } PathLine { x: path_view1.width / 2; y: path_view1.height / 2} PathAttribute { name: "iconOpacity"; value: 1.0 } PathLine { x: path_view1.width; y: path_view1.height / 2} PathAttribute { name: "iconOpacity"; value: 0.5 } }
  • 14. QML in C++ applications  Use QDeclarativeView to embed QML  QGraphicsView subclass, QWidget's as well  Useful to add QML features on top of already existing applications  Keep an eye on startup time and memory usage 14
  • 15. QML in C++ applications  QML functions can be called via QMetaObject::invokeMethod()  QML objects can emit signals that C++ code can QObject::connect()  → you can define an interface for QML objects  C++ properties / signals / slots are exposed to QML via the Meta Object System 15
  • 16. QML Models in C++  QML doesn't have direct access to hardware  What if we want to retrieve a list of channel from a TV tuner?  We can subclass QAbstractItemModel, implement the desired model in C++ and use it from QML. 16
  • 17. The TV menu  Two states:  TV only  overlay on screen  A channel list (reusable component)  A C++ model to retrieve channels 17
  • 18. Putting it all together  Fast forward: we have several QML files, one for each page  We would like to “instantiate” and load a QML file on-the-fly 18
  • 19. Dynamic Object Management  Dynamic object creation from Javascript  Qt.createComponent(url) → Component  Component.createObject(parent) → inst  The QML file can be fetched over the network  Great for implementing live widgets!  … but the fetch is asynchronous: how do I know when it's finished? 19
  • 20. Dynamic Object Management function createObject() { component = Qt.createComponent("Sprite.qml"); if (component.status == Component.Ready) finishCreation(); else component.statusChanged.connect(finishCreation); } function finishCreation() { if (component.status == Component.Ready) { sprite = component.createObject(appWindow); // … } } 20
  • 21. A stack of pages  In most STBs, pages are in a stack  Entering a page → push  Previous page → pop  Panic button (home menu) → clear  We need a persistent global state for this 21
  • 22. Stack implementation // Stack.js var stack = [] // Create a QML object from a given filename and push it on the stack function openPage(filename) { var page_c = Qt.createComponent(filename) var page = page_c.createObject(root_window) stack.push(page) return page } // Page.qml Import “stack.js” as Stack Page { Keys.onReturnPressed: { Stack.openPage(“tvmenu.qml”) } } 22
  • 23. Stack implementation  Sounds great! ...But alas, it doesn't work  A new execution context is created for the use of the importing Component only  QML JS can't modify global object members either  .pragma library  Placed at the top of a JS module, tells QML that this module is stateless, so it's instance can freely shared  Handle with care 23
  • 24. THANKS ! Develer S.r.l. Via Mugellese 1/A 50013 Campi Bisenzio Firenze - Italy Contacts Mail: info@develer.com Phone: +39-055-3984627 Fax: +39 178 6003614 http://www.develer.com