cross-platform ui for c++ apps using qml at quartzq€¦ · •mvc architecture in qt • 3...

35
Cross-Platform UI for C++ Apps Using QML at Quartz Lucas Danzinger March 8–11, 2016 | Palm Springs, CA Esri Developer Summit

Upload: others

Post on 18-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Cross-Platform UI for C++ Apps Using QML at Quartz

Lucas Danzinger

March 8–11, 2016 | Palm Springs, CA

Esri Developer Summit

Page 2: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

C++ UI Options

• wxWidgets• GTK+ (GIMP Toolkit)• FLTK (Fast Light Toolkit)• Qt

Page 3: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Qt FrameworkQt Quick & QML

Page 4: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Agenda

• Qt Quick & QML• Benefits of QML for C++ devs• Benefits of C++ for QML devs• Integrating C++ and QML

Page 5: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

What is Qt Quick?

Page 6: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

What is Qt Quick

• Implies QML• Modern UI Framework• Separates declarative UI (QML) with procedural business logic (C++)• High performance• Native cross platform

- Supports nearly any platform- Scales well- Support for touch

Page 7: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

QML

Highly readableJSON syntax

Dynamic property binding async communication via signal and handler

Page 8: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Why use C++ and Qt Quick?It depends…

Page 9: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Benefits of Qt Quick for C++ Devs

• Dynamic user interfaces• Fluid animation• Separate UI and business logic

- Designer focus on UI- Developer focus on functionality

• Cross platform- Scales well for touch screens

• Rapid UI Development• Speedy performance

Page 10: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Benefits of Qt Quick for C++ Devs

Qt WidgetsQt Quick

Page 11: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Benefits of C++ for QML Devs

• QML is designed for UI• Declarative QML === great• Imperative QML < great• Performance

- Loops- String parsing- Workerscript

Page 12: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

QML vs C++ Performance Comparison

Page 13: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

How to integrate C++ and QML

Page 14: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Your map-app pattern

• Qt Widgets or Qt Quick?• MapView types• 10.2.6 Options:

- Pure QML API - Pure C++ API (using Qt Widgets)

• Quartz Options:- The same as 10.2.6- Plus a C++ API with QML MapView

Page 15: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Display a Map in QML

Page 16: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

“Hello World” Map App with C++ & QML

Page 17: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

MapQuickView with C++ and QMLRegister classes in your main.cpp

• Register your C++ Class with QML

• Register your C++ MapView with QML

Page 18: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

MapQuickView with C++ and QMLDeclare objects in your QML

• Import the namespace you registered

• Declare your C++ class (which inherits from QQuickItem)

• Declare your MapView and give it an ID

Page 19: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

MapQuickView with C++ and QMLAdd a Map to your MapView in C++

• Find the QML Object in C++

• Create a Map and add to MapView

Page 20: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Functions

Page 21: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Executing C++ functions from QML

Page 22: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Invokable C++ functionCall a C++ function from QML

• Add function declaration

• Use Q_INVOKABLE macro

• Implement the member function

• Call from QML

Page 23: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Properties

Page 24: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Bindable Properties

Page 25: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Bindable PropertiesC++ header declaration

• Create a getter

• Create member to hold property value

• Create signal

• Use Q_PROPERTY macro

Page 26: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Bindable Properties (cont)C++ implementation

• Set a value on the member• Emit the signal

• Implement the getter

Page 27: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Bindable Properties (cont)QML implementation

• Bind to the property

• Connect to signals viasignal handlers

Page 28: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Models and Views

Page 29: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Models and Views

• MVC architecture in Qt• 3 components of this system in Qt

- Model – contains the data- Delegate – UI element that determines how each item in the

model will be displayed- View - Displays a delegate for each item in the model

• Models automatically notify the view to update when data changes

• You can bind list properties to QML Views

Page 30: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Models and Views

Page 31: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Models and Views

• Expose as a Q_PROPERTY

• Register ListModel with QML

• Consume in QML

Page 32: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Recap

• Qt Quick & QML• Benefits of QML for C++ devs• Benefits of C++ for QML devs• Integrating C++ and QML

- Displaying a map- Calling functions- Binding to properties- Using Models and Views

Page 33: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Related sessions

• Cross-platform Native App Development with Qt/QML- Thursday 2:30 – 3:30 pm in Demo Theater 3

• The Road Ahead: ArcGIS Runtime- Thursday 5:30 – 6:30 pm in Primrose A

Page 34: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that

Questions?

Page 35: Cross-Platform UI for C++ Apps Using QML at Quartzq€¦ · •MVC architecture in Qt • 3 components of this system in Qt-Model – contains the data-Delegate – UI element that