SlideShare uma empresa Scribd logo
1 de 35
Baixar para ler offline
Serving QML applications over the network




                            Jeremy Lainé
                               Wifirst
Jeremy Lainé


 ●
  Using Qt since 2001 (desktop, mobile, embedded)


 ●
  Occasional Qt contributor (QDnsLookup)


 ●
  Head of software development at Wifirst (ISP)


 ●
  Lead developer of a IM / VoIP app for Wifirst
 customers
     2 / 35
Overview



 1. Why serve applications over the network?


 2. QML network transparency


 3. Building your application


 4. Deploying your application

      3 / 35
1. Why serve applications over the network?




                                              4
Typical application deployment


 ●
  Development
 ●
  Packaging
 ●
  In-house beta testing
 ●
  Push application to all users
 ●
  Repeat!

        Each iteration requires per-
        Each iteration requires per-
        platform installers and an update.
        platform installers and an update.
Options for handling updates


 ●
  Manual updates
     Most users cannot be bothered to update
     ●



     You end up with a heterogeneous installed base
     ●



     Your cool new features don't reach your users!
     ●




 ●
  Automatic updates
     Not all platforms have an “application store”
     ●



     Each platform requires specific packaging wok
     ●



     Usually requires elevated permissions (Windows UAC..)
     ●




         6 / 35
Updates are hard!




       Not convinced? Look at the Chrome
       Not convinced? Look at the Chrome
       and Firefox codebases!
       and Firefox codebases!
     7 / 35
How about QML apps?


 ●
  C++ wrapper code:
     ●
         has usual deployment constraints


 ●
  QML / Javascript code and resources:
     fully cross-platform
     ●



     conveniently split into multiple files
     ●



     can be loaded over the network by QtQuick
     ●




         8 / 35
Some benefits


 ●
  Faster iteration and testing
 ●
  Fix bugs after release!
 ●
  Progressive update roll-out
 ●
  Split testing for UI changes
 ●
  Time-limited changes (Christmas specials!)




     9 / 35
2. QML network transparency




                              10
Loading QML from C++



  QDeclarativeView (Qt4) and QQuickView (Qt5)
  support loading from an HTTP URL

  int main(int argc, char *argv[])
  {
    QApplication app(argc, argv);

      QQuickView view;
      view.setSource(QUrl(“http://foo.com/main.qml”));
      view.show();

      return app.exec();
  }


      11 / 35
QML “loader” elements



 Built-in QML elements with a “source” property
 support HTTP URLs
  ●
   Image
  ●
   Loader
  ●
   FontLoader
                Image {
                  source: “http://foo.com/bar.img”
                }



      12 / 35
Relative URLs


 Relative URLs are resolved relative to the QML
 document's URL
 Image {
   source: “head.jpg”
 }
   file:///home/bob/foo.qml         file:///home/bob/head.jpg


 Image {
   source: “head.jpg”
 }
   http://example.com/foo.qml      http://example.com/head.jpg

 You can use the same code locally and remotely!
 You can use the same code locally and remotely!
      13 / 35
QML network transparency


 ●
  QML type declarations can be served over HTTP,
 but you need to list your types in a “qmldir” file:
               Button 1.0 Button.qml
               CheckBox 1.0 CheckBox.qml



 ●
  Javascript code can be served over HTTP
          import “scripts/utils.js” as Utils




     14 / 35
Translations

●
 Loading translations from QML is missing
●
 You can provide your own TranslationLoader and do
    TranslationLoader {
       source: “i18n/my_translation.qm”

           onStatusChanged: {
              Console.log(“status is: “ + status);
           }
    }
●
 A proposal for including it in Qt5
 https://codereview.qt-project.org/#change,31864

        15 / 35
3. Building your application




                               16
General recommendations


 ●
  Split models and presentation
 ●
  The C++ code still needs traditional updates
     Make the loader robust
     ●



     Keep the API simple
     ●



     Keep the API stable
     ●


 ●
  Serve all the rest on the fly
     QML and Javascript code
     ●



     Resources (images, fonts, translations)
     ●




         17 / 35
Application architecture


                                   fontawesome.ttf

                  background.png
Remote content
                                                     Button.qml

                                   main.qml




Local C++ code       Application                Plugins




        18 / 35
The application


 ●
  Creates the QML view


 ●
  Sets up the QNetworkAccessManager


 ●
  Loads a single “root” QML file over the network


 ●
  Can fallback to local files for offline use


     19 / 35
Application / setting up QNAM


 ●
  Give your application a User-Agent
     Helps track usage, or serve different content
     ●



     QtWebkit generated request already have a UA
     ●


 ●
  Specify the preferred language (Accept-Language)
 ●
  Set up a persistent network cache
 ●
  Configure HTTP pipelining




         20 / 35
Application / caching


 ●
  QtQuick caches components + pixmaps (memory)
 ●
  QNAM supports “If-Modified-Since” but needs a
 persistent disk cache
class MyFactory : public QQmlNetworkAccessManagerFactory
{
public:
    QNetworkAccessManager* create(QObject* parent)
    {
        QNetworkAccessManager* manager = new QNetworkAccessManager(parent);
        QNetworkDiskCache* cache = new QNetworkDiskCache(manager);
        cache->setCacheDirectory(“/some/directory/”);
        manager->setCache(cache);
        return manager;
    }
};

view->engine()->setNetworkAccessManagerFactory(new MyFactory());


      21 / 35
Application / HTTP pipelining


 ●
  Splitting QML into files: good but incurs overhead
 HTTP/1.1 allows sending multiple requests
 ●


 without waiting for replies
     Particularly useful for high latency links
     ●


 ●
  Qt5 uses pipelining for all resources
 ●
  Qt4 only uses pipelining for pixmaps and fonts
     ●
         subclass QNetworkAccessManager if needed



         22 / 35
Application / offline use



  At startup, fall back to a bundled copy of your
  ●


  QML code if loading from network fails

void MyView::onStatusChanged(QQuickView::Status status)
{
   if (status == QQuickView::Error && useNetwork) {
      useNetwork = false;
      setSource(QUrl(“qrc://main.qml”));
   }
}


  Catching errors later is harder..
  ●



      23 / 35
Plugins


 ●
  Define data models and scriptable objects


 ●
  Keep the C++ code simple : if something can be
 done in QML instead, do it!


 ●
  Keep the API stable : if you change it, you will
 probably need different QML files



     24 / 35
QML content


 ●
  Welcome to an asynchronous world!

var component = Qt.createComponent(source);
var object = component.createObject(parent);           BAD


 var component = Qt.createComponent(source);
 if (component.status == Component.Loading)
    component.statusChanged.connect(finishCreation);
 else
    finishCreation();
                                                       GOOD
 function finishCreation() {
    if (component.status == Component.Ready) {
       var object = component.createObject(parent);
    }
 }

      25 / 35
QML content


 ●
  Review your timing assumptions!
     Do not depend on objects loading in a set order
     ●



     Use Component.onCompleted with care
     ●




 ●
  Having lots of icons can be a problem, consider
 using web fonts like FontAwesome




         26 / 35
4. Deploying your application




                                27
Hosting the QML code



 ●
  You have all the usual web hosting options
     Run your own servers (nginx, apache, ..)
     ●



     Use cloud services
     ●



     Do load-balancing, fail-over, etc..
     ●




 ●
  QML files can be 100% static files, or even
 generated on the fly



         28 / 35
Version your root URL


 ●
  Plan for multiple versions of your C++ app, as the
 API will probably change, e.g. :
 http://example.com/myapp/1.0/main.qml
 http://example.com/myapp/1.1/main.qml


 ●
  Alternatively, switch on User-Agent




     29 / 35
Cache “consistency”


 ●
  Consider two related files Dialog.qml and
 Button.qml, which must be in the same version to
 work
 ●
  Caching can cause inconsistency
 App start 1       User click 1          App start 2   User click 2


                         Button.qml                           Button.qml
                          version 1                            version 1   FAIL!

      Dialog.qml                               Dialog.qml
      version 1                                version 2


                                  time
       30 / 35
Cache “consistency”


 ●
  Your main.qml can load all subsequent contents
 from a subdirectory to “version” the QML code


 ●
  Layout:
     main.qml
     ●



     RELEASE_ID/Button.qml
     ●



     RELEASE_ID/Dialog.qml
     ●




         31 / 35
Security


 ●
  Make use of HTTPS to avoid your application
 loading malicious code (DNS hijacking)


 ●
  Make sure your certificates are valid!


 ●
  Some platforms or custom certificates will require
 adding your CA certificates
     QSslSocket::addDefaultCaCertificates(“./myca.pem”);


        32 / 35
Performance considerations


 ●
  Enable gzip compression for QML and JS files


 ●
  Set an Expires header to avoid QNAM re-checking
 all files on startups


 ●
  Serve from a cookie-less domain




     33 / 35
5. Questions




               34
Get the code




 ●
  Source code for the Wifirst IM / VoIP client



     git clone git://git.wifirst.net/wilink.git




     35 / 35

Mais conteúdo relacionado

Mais procurados

Basics of Model/View Qt programming
Basics of Model/View Qt programmingBasics of Model/View Qt programming
Basics of Model/View Qt programmingICS
 
Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Janel Heilbrunn
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UIOpenBossa
 
Qt test framework
Qt test frameworkQt test framework
Qt test frameworkICS
 
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 developmentICS
 
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 3ICS
 
Qt Internationalization
Qt InternationalizationQt Internationalization
Qt InternationalizationICS
 
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 4ICS
 
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 moreICS
 
Lockless Producer Consumer Threads: Asynchronous Communications Made Easy
Lockless Producer Consumer Threads: Asynchronous Communications Made EasyLockless Producer Consumer Threads: Asynchronous Communications Made Easy
Lockless Producer Consumer Threads: Asynchronous Communications Made EasyICS
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickICS
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? ICS
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4ICS
 
Fun with QML
Fun with QMLFun with QML
Fun with QMLICS
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...ICS
 

Mais procurados (20)

QtQuick Day 1
QtQuick Day 1QtQuick Day 1
QtQuick Day 1
 
Basics of Model/View Qt programming
Basics of Model/View Qt programmingBasics of Model/View Qt programming
Basics of Model/View Qt programming
 
Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2Best Practices in Qt Quick/QML - Part 2
Best Practices in Qt Quick/QML - Part 2
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UI
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
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
 
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
 
Qt Internationalization
Qt InternationalizationQt Internationalization
Qt Internationalization
 
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
 
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
 
Lockless Producer Consumer Threads: Asynchronous Communications Made Easy
Lockless Producer Consumer Threads: Asynchronous Communications Made EasyLockless Producer Consumer Threads: Asynchronous Communications Made Easy
Lockless Producer Consumer Threads: Asynchronous Communications Made Easy
 
Qt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt QuickQt for Beginners Part 3 - QML and Qt Quick
Qt for Beginners Part 3 - QML and Qt Quick
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
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
 
Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4
 
Fun with QML
Fun with QMLFun with QML
Fun with QML
 
QtQuick Day 2
QtQuick Day 2QtQuick Day 2
QtQuick Day 2
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 

Semelhante a Serving QML applications over the network

Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Annie Huang
 
A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...
A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...
A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...Igalia
 
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)Igalia
 
Xpdays: Kubernetes CI-CD Frameworks Case Study
Xpdays: Kubernetes CI-CD Frameworks Case StudyXpdays: Kubernetes CI-CD Frameworks Case Study
Xpdays: Kubernetes CI-CD Frameworks Case StudyDenys Vasyliev
 
Update on the open source browser space (16th GENIVI AMM)
Update on the open source browser space (16th GENIVI AMM)Update on the open source browser space (16th GENIVI AMM)
Update on the open source browser space (16th GENIVI AMM)Igalia
 
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius SchumacherOSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius SchumacherNETWAYS
 
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...Igalia
 
Chromium: NaCl and Pepper API
Chromium: NaCl and Pepper APIChromium: NaCl and Pepper API
Chromium: NaCl and Pepper APIChang W. Doh
 
Andreas Jakl, Qt Symbian Maemo Quickstart
Andreas Jakl, Qt Symbian Maemo QuickstartAndreas Jakl, Qt Symbian Maemo Quickstart
Andreas Jakl, Qt Symbian Maemo QuickstartNokiaAppForum
 
OpenMP-OpenACC-Offload-Cauldron2022-1.pdf
OpenMP-OpenACC-Offload-Cauldron2022-1.pdfOpenMP-OpenACC-Offload-Cauldron2022-1.pdf
OpenMP-OpenACC-Offload-Cauldron2022-1.pdfssuser866937
 
To Russia with Love: Deploying Kubernetes in Exotic Locations On Prem
To Russia with Love: Deploying Kubernetes in Exotic Locations On PremTo Russia with Love: Deploying Kubernetes in Exotic Locations On Prem
To Russia with Love: Deploying Kubernetes in Exotic Locations On PremCloudOps2005
 
Extended and embedding: containerd update & project use cases
Extended and embedding: containerd update & project use casesExtended and embedding: containerd update & project use cases
Extended and embedding: containerd update & project use casesPhil Estes
 
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...Haggai Philip Zagury
 
ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureYury Tsarev
 
Guided overview of software frameworks qt framework
Guided overview of software frameworks   qt frameworkGuided overview of software frameworks   qt framework
Guided overview of software frameworks qt frameworkBenjamin Cottrell
 
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...Oleg Shalygin
 
WebKit2 And You (GUADEC 2013)
WebKit2 And You (GUADEC 2013)WebKit2 And You (GUADEC 2013)
WebKit2 And You (GUADEC 2013)Igalia
 

Semelhante a Serving QML applications over the network (20)

Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
 
OpenCms Days 2015 Workflow using Docker and Jenkins
OpenCms Days 2015 Workflow using Docker and JenkinsOpenCms Days 2015 Workflow using Docker and Jenkins
OpenCms Days 2015 Workflow using Docker and Jenkins
 
A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...
A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...
A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...
 
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
HTML5 on the AGL demo platform with Chromium and WAM (AGL AMM March 2021)
 
Xpdays: Kubernetes CI-CD Frameworks Case Study
Xpdays: Kubernetes CI-CD Frameworks Case StudyXpdays: Kubernetes CI-CD Frameworks Case Study
Xpdays: Kubernetes CI-CD Frameworks Case Study
 
Update on the open source browser space (16th GENIVI AMM)
Update on the open source browser space (16th GENIVI AMM)Update on the open source browser space (16th GENIVI AMM)
Update on the open source browser space (16th GENIVI AMM)
 
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
 
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius SchumacherOSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
OSDC 2018 | Highly Available Cloud Foundry on Kubernetes by Cornelius Schumacher
 
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
WPEWebKit, the WebKit port for embedded platforms (Linaro Connect San Diego 2...
 
JenkinsCI
JenkinsCIJenkinsCI
JenkinsCI
 
Chromium: NaCl and Pepper API
Chromium: NaCl and Pepper APIChromium: NaCl and Pepper API
Chromium: NaCl and Pepper API
 
Andreas Jakl, Qt Symbian Maemo Quickstart
Andreas Jakl, Qt Symbian Maemo QuickstartAndreas Jakl, Qt Symbian Maemo Quickstart
Andreas Jakl, Qt Symbian Maemo Quickstart
 
OpenMP-OpenACC-Offload-Cauldron2022-1.pdf
OpenMP-OpenACC-Offload-Cauldron2022-1.pdfOpenMP-OpenACC-Offload-Cauldron2022-1.pdf
OpenMP-OpenACC-Offload-Cauldron2022-1.pdf
 
To Russia with Love: Deploying Kubernetes in Exotic Locations On Prem
To Russia with Love: Deploying Kubernetes in Exotic Locations On PremTo Russia with Love: Deploying Kubernetes in Exotic Locations On Prem
To Russia with Love: Deploying Kubernetes in Exotic Locations On Prem
 
Extended and embedding: containerd update & project use cases
Extended and embedding: containerd update & project use casesExtended and embedding: containerd update & project use cases
Extended and embedding: containerd update & project use cases
 
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
DevOpsDays Tel Aviv DEC 2022 | Building A Cloud-Native Platform Brick by Bric...
 
ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven Infrastructure
 
Guided overview of software frameworks qt framework
Guided overview of software frameworks   qt frameworkGuided overview of software frameworks   qt framework
Guided overview of software frameworks qt framework
 
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
 
WebKit2 And You (GUADEC 2013)
WebKit2 And You (GUADEC 2013)WebKit2 And You (GUADEC 2013)
WebKit2 And You (GUADEC 2013)
 

Último

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Último (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Serving QML applications over the network

  • 1. Serving QML applications over the network Jeremy Lainé Wifirst
  • 2. Jeremy Lainé ● Using Qt since 2001 (desktop, mobile, embedded) ● Occasional Qt contributor (QDnsLookup) ● Head of software development at Wifirst (ISP) ● Lead developer of a IM / VoIP app for Wifirst customers 2 / 35
  • 3. Overview 1. Why serve applications over the network? 2. QML network transparency 3. Building your application 4. Deploying your application 3 / 35
  • 4. 1. Why serve applications over the network? 4
  • 5. Typical application deployment ● Development ● Packaging ● In-house beta testing ● Push application to all users ● Repeat! Each iteration requires per- Each iteration requires per- platform installers and an update. platform installers and an update.
  • 6. Options for handling updates ● Manual updates Most users cannot be bothered to update ● You end up with a heterogeneous installed base ● Your cool new features don't reach your users! ● ● Automatic updates Not all platforms have an “application store” ● Each platform requires specific packaging wok ● Usually requires elevated permissions (Windows UAC..) ● 6 / 35
  • 7. Updates are hard! Not convinced? Look at the Chrome Not convinced? Look at the Chrome and Firefox codebases! and Firefox codebases! 7 / 35
  • 8. How about QML apps? ● C++ wrapper code: ● has usual deployment constraints ● QML / Javascript code and resources: fully cross-platform ● conveniently split into multiple files ● can be loaded over the network by QtQuick ● 8 / 35
  • 9. Some benefits ● Faster iteration and testing ● Fix bugs after release! ● Progressive update roll-out ● Split testing for UI changes ● Time-limited changes (Christmas specials!) 9 / 35
  • 10. 2. QML network transparency 10
  • 11. Loading QML from C++ QDeclarativeView (Qt4) and QQuickView (Qt5) support loading from an HTTP URL int main(int argc, char *argv[]) { QApplication app(argc, argv); QQuickView view; view.setSource(QUrl(“http://foo.com/main.qml”)); view.show(); return app.exec(); } 11 / 35
  • 12. QML “loader” elements Built-in QML elements with a “source” property support HTTP URLs ● Image ● Loader ● FontLoader Image { source: “http://foo.com/bar.img” } 12 / 35
  • 13. Relative URLs Relative URLs are resolved relative to the QML document's URL Image { source: “head.jpg” } file:///home/bob/foo.qml file:///home/bob/head.jpg Image { source: “head.jpg” } http://example.com/foo.qml http://example.com/head.jpg You can use the same code locally and remotely! You can use the same code locally and remotely! 13 / 35
  • 14. QML network transparency ● QML type declarations can be served over HTTP, but you need to list your types in a “qmldir” file: Button 1.0 Button.qml CheckBox 1.0 CheckBox.qml ● Javascript code can be served over HTTP import “scripts/utils.js” as Utils 14 / 35
  • 15. Translations ● Loading translations from QML is missing ● You can provide your own TranslationLoader and do TranslationLoader { source: “i18n/my_translation.qm” onStatusChanged: { Console.log(“status is: “ + status); } } ● A proposal for including it in Qt5 https://codereview.qt-project.org/#change,31864 15 / 35
  • 16. 3. Building your application 16
  • 17. General recommendations ● Split models and presentation ● The C++ code still needs traditional updates Make the loader robust ● Keep the API simple ● Keep the API stable ● ● Serve all the rest on the fly QML and Javascript code ● Resources (images, fonts, translations) ● 17 / 35
  • 18. Application architecture fontawesome.ttf background.png Remote content Button.qml main.qml Local C++ code Application Plugins 18 / 35
  • 19. The application ● Creates the QML view ● Sets up the QNetworkAccessManager ● Loads a single “root” QML file over the network ● Can fallback to local files for offline use 19 / 35
  • 20. Application / setting up QNAM ● Give your application a User-Agent Helps track usage, or serve different content ● QtWebkit generated request already have a UA ● ● Specify the preferred language (Accept-Language) ● Set up a persistent network cache ● Configure HTTP pipelining 20 / 35
  • 21. Application / caching ● QtQuick caches components + pixmaps (memory) ● QNAM supports “If-Modified-Since” but needs a persistent disk cache class MyFactory : public QQmlNetworkAccessManagerFactory { public: QNetworkAccessManager* create(QObject* parent) { QNetworkAccessManager* manager = new QNetworkAccessManager(parent); QNetworkDiskCache* cache = new QNetworkDiskCache(manager); cache->setCacheDirectory(“/some/directory/”); manager->setCache(cache); return manager; } }; view->engine()->setNetworkAccessManagerFactory(new MyFactory()); 21 / 35
  • 22. Application / HTTP pipelining ● Splitting QML into files: good but incurs overhead HTTP/1.1 allows sending multiple requests ● without waiting for replies Particularly useful for high latency links ● ● Qt5 uses pipelining for all resources ● Qt4 only uses pipelining for pixmaps and fonts ● subclass QNetworkAccessManager if needed 22 / 35
  • 23. Application / offline use At startup, fall back to a bundled copy of your ● QML code if loading from network fails void MyView::onStatusChanged(QQuickView::Status status) { if (status == QQuickView::Error && useNetwork) { useNetwork = false; setSource(QUrl(“qrc://main.qml”)); } } Catching errors later is harder.. ● 23 / 35
  • 24. Plugins ● Define data models and scriptable objects ● Keep the C++ code simple : if something can be done in QML instead, do it! ● Keep the API stable : if you change it, you will probably need different QML files 24 / 35
  • 25. QML content ● Welcome to an asynchronous world! var component = Qt.createComponent(source); var object = component.createObject(parent); BAD var component = Qt.createComponent(source); if (component.status == Component.Loading) component.statusChanged.connect(finishCreation); else finishCreation(); GOOD function finishCreation() { if (component.status == Component.Ready) { var object = component.createObject(parent); } } 25 / 35
  • 26. QML content ● Review your timing assumptions! Do not depend on objects loading in a set order ● Use Component.onCompleted with care ● ● Having lots of icons can be a problem, consider using web fonts like FontAwesome 26 / 35
  • 27. 4. Deploying your application 27
  • 28. Hosting the QML code ● You have all the usual web hosting options Run your own servers (nginx, apache, ..) ● Use cloud services ● Do load-balancing, fail-over, etc.. ● ● QML files can be 100% static files, or even generated on the fly 28 / 35
  • 29. Version your root URL ● Plan for multiple versions of your C++ app, as the API will probably change, e.g. : http://example.com/myapp/1.0/main.qml http://example.com/myapp/1.1/main.qml ● Alternatively, switch on User-Agent 29 / 35
  • 30. Cache “consistency” ● Consider two related files Dialog.qml and Button.qml, which must be in the same version to work ● Caching can cause inconsistency App start 1 User click 1 App start 2 User click 2 Button.qml Button.qml version 1 version 1 FAIL! Dialog.qml Dialog.qml version 1 version 2 time 30 / 35
  • 31. Cache “consistency” ● Your main.qml can load all subsequent contents from a subdirectory to “version” the QML code ● Layout: main.qml ● RELEASE_ID/Button.qml ● RELEASE_ID/Dialog.qml ● 31 / 35
  • 32. Security ● Make use of HTTPS to avoid your application loading malicious code (DNS hijacking) ● Make sure your certificates are valid! ● Some platforms or custom certificates will require adding your CA certificates QSslSocket::addDefaultCaCertificates(“./myca.pem”); 32 / 35
  • 33. Performance considerations ● Enable gzip compression for QML and JS files ● Set an Expires header to avoid QNAM re-checking all files on startups ● Serve from a cookie-less domain 33 / 35
  • 35. Get the code ● Source code for the Wifirst IM / VoIP client git clone git://git.wifirst.net/wilink.git 35 / 35