SlideShare a Scribd company logo
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

PDF
Qt everywhere a c++ abstraction platform
PDF
Crossing the border with Qt: the i18n system
PDF
06 - Qt Communication
PDF
Qt for beginners
PPTX
Qt Framework Events Signals Threads
PPT
A synchronous scheduling service for distributed real-time Java
ODP
Cross Platform Qt
Qt everywhere a c++ abstraction platform
Crossing the border with Qt: the i18n system
06 - Qt Communication
Qt for beginners
Qt Framework Events Signals Threads
A synchronous scheduling service for distributed real-time Java
Cross Platform Qt

What's hot (20)

PDF
QThreads: Are You Using Them Wrong?
 
PPT
PDF
Building the QML Run-time
PPT
No Heap Remote Objects for Distributed real-time Java
PPT
Qt for S60
PPT
Clockless design language - ilia greenblat
PPT
Enhancing the region model of RTSJ
PPTX
Java 7 & 8
PPT
Stackless Python In Eve
PDF
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
PPTX
NvFX GTC 2013
PDF
S emb t13-freertos
PPT
Simple asynchronous remote invocations for distributed real-time Java
PPTX
vkFX: Effect(ive) approach for Vulkan API
PDF
Java Concurrency Gotchas
PDF
NIR on the Mesa i965 backend (FOSDEM 2016)
PDF
State of the Art OpenGL and Qt
 
PDF
Parallel R
PDF
Integrazione QML / C++
PDF
Open cl programming using python syntax
QThreads: Are You Using Them Wrong?
 
Building the QML Run-time
No Heap Remote Objects for Distributed real-time Java
Qt for S60
Clockless design language - ilia greenblat
Enhancing the region model of RTSJ
Java 7 & 8
Stackless Python In Eve
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
NvFX GTC 2013
S emb t13-freertos
Simple asynchronous remote invocations for distributed real-time Java
vkFX: Effect(ive) approach for Vulkan API
Java Concurrency Gotchas
NIR on the Mesa i965 backend (FOSDEM 2016)
State of the Art OpenGL and Qt
 
Parallel R
Integrazione QML / C++
Open cl programming using python syntax
Ad

Viewers also liked (13)

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

Similar to Qt Quick in depth (20)

PDF
Best Practices in Qt Quick/QML - Part II
 
PDF
Best Practices in Qt Quick/QML - Part 1 of 4
 
PPTX
UI Programming with Qt-Quick and QML
PPTX
Best Practices in Qt Quick/QML - Part I
 
PDF
Serving QML applications over the network
PDF
In-Depth Model/View with QML
 
PDF
Qt and QML performance tips & tricks for Qt 4.7
PDF
Ubuntu app development
PDF
Best Practices in Qt Quick/QML - Part 2
PDF
Best Practices in Qt Quick/QML - Part 2
 
ODP
Intro to QML / Declarative UI
PPTX
Qt quick at Cybercom Developer Day 2010 by Alexis Menard 7.9.2010
PDF
Best Practices in Qt Quick/QML - Part IV
 
PPTX
Witekio custom modern qt quick components
PDF
Qt for Beginners Part 3 - QML and Qt Quick
 
PDF
Fun with QML
 
PDF
Best Practices in Qt Quick/QML - Part III
 
PDF
The Next Generation Qt Item Views
PDF
Qt Itemviews, The Next Generation
PDF
Angry Developer: Creating a Game in QML and JavaScript for MeeGo N9 @iRajLal
Best Practices in Qt Quick/QML - Part II
 
Best Practices in Qt Quick/QML - Part 1 of 4
 
UI Programming with Qt-Quick and QML
Best Practices in Qt Quick/QML - Part I
 
Serving QML applications over the network
In-Depth Model/View with QML
 
Qt and QML performance tips & tricks for Qt 4.7
Ubuntu app development
Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2
 
Intro to QML / Declarative UI
Qt quick at Cybercom Developer Day 2010 by Alexis Menard 7.9.2010
Best Practices in Qt Quick/QML - Part IV
 
Witekio custom modern qt quick components
Qt for Beginners Part 3 - QML and Qt Quick
 
Fun with QML
 
Best Practices in Qt Quick/QML - Part III
 
The Next Generation Qt Item Views
Qt Itemviews, The Next Generation
Angry Developer: Creating a Game in QML and JavaScript for MeeGo N9 @iRajLal

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

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

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine Learning_overview_presentation.pptx
Spectroscopy.pptx food analysis technology
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
Programs and apps: productivity, graphics, security and other tools
Per capita expenditure prediction using model stacking based on satellite ima...
MIND Revenue Release Quarter 2 2025 Press Release
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation_ Review paper, used for researhc scholars
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Assigned Numbers - 2025 - Bluetooth® Document
The Rise and Fall of 3GPP – Time for a Sabbatical?
Digital-Transformation-Roadmap-for-Companies.pptx
A comparative analysis of optical character recognition models for extracting...
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.

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