SlideShare a Scribd company logo
Qt Hybrid Apps
                                 Ynon Perek




Tuesday, February 14, 2012
Native Is Broken

                    • Deployment is pain

                    • Change is complex
                      for users

                    • Managing versions
                      is a pain for devs




Tuesday, February 14, 2012
Qt Is Broken

                    • Writing a unique UI
                      is not easy

                    • Can’t reuse code
                      from existing
                      web apps




Tuesday, February 14, 2012
Hybrid is the new App

                    • Enjoy constant
                      deployment - like a
                      web site

                    • Enjoy unique UI

                    • Enjoy native code




Tuesday, February 14, 2012
Agenda

                    • Hybrid Architecture
                    • Choosing Hybrid
                    • Bridging The Gap
                    • Tips



Tuesday, February 14, 2012
Hybrid Arch
                    • Native Qt wrapper
                      acts as a browser

                    • All User Interface
                      and Application           HTML/JS/CSS
                      logic is coded in JS

                    • Extra functionality
                      is provided in C++     Qt C++ (Native Code)



Tuesday, February 14, 2012
Hybrid Code

                    • A special object is inserted to JS from
                      the Qt wrapper application
                    • Calling methods on this object leads to
                      execution of code in C++
                    • Defaults to single-threaded



Tuesday, February 14, 2012
Hybrid: When

                    • Flexible or unique UI
                    • Reuse existing web code
                    • Embed dynamic content from the net
                    • Thin Client
                    • An experienced FED on your team


Tuesday, February 14, 2012
Hybrid: Code

                    • QWebPage is a QObject designed to
                      view and edit web documents
                    • QWebFrame is a QObject representing a
                      frame or iframe in a page
                    • QWebView is a QWidget capable of
                      displaying QWebPage


Tuesday, February 14, 2012
Demo
                        Display Web Content in a QWebView




Tuesday, February 14, 2012
Bridging The
            Gap
            Use Qt Webkit Bridge to
           connect web content with
                 native code




                                      http://www.flickr.com/photos/groundzero/73471268/
Tuesday, February 14, 2012
Accessing QObjects

                    • By default, no QObject is accessible
                      through the web environment
                    • Call QWebFrame’s
                      addToJavaScriptWindowObject
                      to add a QObject



Tuesday, February 14, 2012
Accessing QObjects

         // QWebView has a page() method to return
         // the active QWebPage
         QWebFrame *frame = myWebPage->mainFrame();
         frame->addToJavaScriptWindowObject("someNameForMyObject",
                                             myObject);
         // ...




Tuesday, February 14, 2012
Invokable Methods
   class Zombie : public QObject
   {
                                        • All slots in the
        Q_OBJECT                          QObject can
   public:                                be invoked
        Q_INVOKABLE void eatBrain();      from JS
        Q_INVOKABLE int attack();

        void rest();                    • Can use
   public slots:                          Q_INVOKABLE
        void walk(QString where);         to define an
                                          invokable
   };
                                          method



Tuesday, February 14, 2012
Demo
                             Call C++ Code From JS




Tuesday, February 14, 2012
Signal & Slots

                    • Signals & Slots are used to call JS Code
                      from C++
                    • Define a signal in the QObject
                    • Use connect to bind that signal to a JS
                      function



Tuesday, February 14, 2012
Signals & Slots
  class Zombie : public QObject
  {
       Q_OBJECT                             • Assume
                                              Zombie was
  signals:
    void scream(int volume);                  added to the
  };                                          page and
                                              named
  function freeze_in_panic(volume) {
     // Oh no it’s the end-of-the-world
                                              Zombie
  }
                                            • Arguments
  Zombie.scream.connect(freeze_in_panic);
                                              must match


Tuesday, February 14, 2012
Passing Data

                    • Arguments are converted when passed
                      between native & web
                    • Failure to match arguments may cause
                      application to crash
                    • Test Everything



Tuesday, February 14, 2012
Data Types
                    • Numbers         • QVariants

                    • Strings         • QObjects

                    • Date & Time     • Pixmaps & Images

                    • Regular         • Web Elements
                      Expressions

                    • Lists

                    • JSON Objects

Tuesday, February 14, 2012
Numbers

                    • Qt numeric types:
                      int, short, float, double, qreal, qint
                    • JavaScript only has Number
                    • Typedefed numbers are not
                      automatically converted



Tuesday, February 14, 2012
Strings

                    • JavaScript’s String is easily translated to
                      QString
                    • Using other types in JS will cause the
                      bridge to attempt conversion by calling
                      toString()



Tuesday, February 14, 2012
Date & Time

                    • Qt has: QDate, QTime & QDateTime
                    • JS has: Date
                    • If JS passed a number to a slot that
                      expected a date, it will be treated as a
                      timestamp



Tuesday, February 14, 2012
Regular Expressions


                    • JavaScript RegEx objects are translated
                      to QRegExp
                    • Can also pass a string




Tuesday, February 14, 2012
Lists

                    • If a slot expects a list, and passed an
                      Array, the bridge will try to convert
                      each element.
                    • Use QVariantList to play safe




Tuesday, February 14, 2012
JSON Objects


                    • A JSON Object translate well to
                      QVariantMap
                    • Use for complex data structures




Tuesday, February 14, 2012
QVariants & QObjects

                    • It’s possible but not recommended to
                      pass QVariants & QObjects as is
                    • For QObject, pass a pointer to expose
                      functionality
                    • Cannot pass any QObject derived



Tuesday, February 14, 2012
Pixmaps & Images
                    • A QImage or
                      QPixmap is              {
                      converted to a JS           width: ...,
                                                  height: ...,
                      object similar to the       toDataURL:
                      right                           function() { ... },

                                                  assignToHTMLImageElement:
                                                      function(element) { ... }
                    • Can send img            }

                      element from web
                      to native


Tuesday, February 14, 2012
QWebElement

                    • Represents a DOM node inside Qt
                    • Used to write custom renderers or
                      extensions to the environment
                    • Not thread-safe




Tuesday, February 14, 2012
Demo
                             Passing Data from Qt to JS




Tuesday, February 14, 2012
Hybrid Tips

                    • Write as little logic as possible in the
                      bridge object
                    • Consider a separate worker thread
                    • Get serious about JavaScript




Tuesday, February 14, 2012
Thanks For Listening

                       Ynon Perek

                       ynonperek@yahoo.com

                       http://ynonperek.com




Tuesday, February 14, 2012

More Related Content

PDF
Domain Driven Design Javaday Roma2007
PDF
All about GWT
PDF
Javascript as a target language - GWT KickOff - Part 2/2
PDF
Clean architecture
PDF
HTML5 - Semantics, struture, and APIs of HTML Documents
PDF
Petri Niemi Qt Web Kit
ODP
Qt 5 - C++ and Widgets
PDF
Hybrid Apps (Native + Web) using WebKit
Domain Driven Design Javaday Roma2007
All about GWT
Javascript as a target language - GWT KickOff - Part 2/2
Clean architecture
HTML5 - Semantics, struture, and APIs of HTML Documents
Petri Niemi Qt Web Kit
Qt 5 - C++ and Widgets
Hybrid Apps (Native + Web) using WebKit

Viewers also liked (11)

PDF
Airports can maximize capacity with minimal capital investment through effect...
PPTX
Qt Memory Management & Signal and Slots
PDF
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
PDF
Creating Slick User Interfaces With Qt
PPT
qt-project.org and Qt 5
PDF
Best Practices in Qt Quick/QML - Part III
 
PPTX
Best Practices in Qt Quick/QML - Part I
 
PDF
더 빠른 웹을 위해: HTTP/2
PDF
Mobile Browser Internal (Blink Rendering Engine)
PDF
Optimizing Performance in Qt-Based Applications
PDF
Model view-delegates-whitepaper
Airports can maximize capacity with minimal capital investment through effect...
Qt Memory Management & Signal and Slots
(NEMO-UX) WAYLAND 기반 윈도우 매니저 소개
Creating Slick User Interfaces With Qt
qt-project.org and Qt 5
Best Practices in Qt Quick/QML - Part III
 
Best Practices in Qt Quick/QML - Part I
 
더 빠른 웹을 위해: HTTP/2
Mobile Browser Internal (Blink Rendering Engine)
Optimizing Performance in Qt-Based Applications
Model view-delegates-whitepaper
Ad

Similar to Hybrid Apps with Qt (20)

PDF
Angular.js - JS Camp UKraine 2013
KEY
Phonegap for Engineers
PDF
Angular 2 overview
PDF
Architecting large Node.js applications
PPTX
Gradle.Enemy at the gates
PDF
QCON SP 2012
PDF
Nodejs
PDF
Devoxx%202008%20Tutorial
PDF
Devoxx%202008%20Tutorial
PPTX
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
PPTX
Couch DB/PouchDB approach for hybrid mobile applications
PDF
Rapid API development on MongoDB
PDF
Building businesspost.ie using Node.js
PDF
Empowering the Social Web with Apache Shindig
PPTX
Node Community Chennai MeetUp1
ODP
Wade.Go Introduction Speech - SFD HCMC 2014
PDF
From Rails legacy to DDD - Pivorak, Lviv
PPTX
Javaone 2013 moscow gradle english
PDF
Cloud Camp Chicago Dec 2012 - All presentations
PDF
Cloud Camp Chicago Dec 2012 Slides
Angular.js - JS Camp UKraine 2013
Phonegap for Engineers
Angular 2 overview
Architecting large Node.js applications
Gradle.Enemy at the gates
QCON SP 2012
Nodejs
Devoxx%202008%20Tutorial
Devoxx%202008%20Tutorial
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Couch DB/PouchDB approach for hybrid mobile applications
Rapid API development on MongoDB
Building businesspost.ie using Node.js
Empowering the Social Web with Apache Shindig
Node Community Chennai MeetUp1
Wade.Go Introduction Speech - SFD HCMC 2014
From Rails legacy to DDD - Pivorak, Lviv
Javaone 2013 moscow gradle english
Cloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 Slides
Ad

More from Ynon Perek (20)

PDF
Regexp
PDF
Html5 intro
PDF
09 performance
PDF
Mobile Web Intro
PDF
Qt multi threads
PDF
Vimperl
PDF
Syllabus
PDF
Mobile Devices
PDF
Network
PDF
Architecture app
PDF
Cryptography
PDF
Unit Testing JavaScript Applications
PDF
How to write easy-to-test JavaScript
PDF
Introduction to Selenium and Ruby
PDF
Introduction To Web Application Testing
PDF
Accessibility
PDF
Angularjs
PDF
Js memory
PDF
Qt Design Patterns
PDF
Web Application Security
Regexp
Html5 intro
09 performance
Mobile Web Intro
Qt multi threads
Vimperl
Syllabus
Mobile Devices
Network
Architecture app
Cryptography
Unit Testing JavaScript Applications
How to write easy-to-test JavaScript
Introduction to Selenium and Ruby
Introduction To Web Application Testing
Accessibility
Angularjs
Js memory
Qt Design Patterns
Web Application Security

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
1. Introduction to Computer Programming.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Tartificialntelligence_presentation.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Building Integrated photovoltaic BIPV_UPV.pdf
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
1. Introduction to Computer Programming.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Tartificialntelligence_presentation.pptx
A Presentation on Artificial Intelligence
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Weekly Chronicles - August'25-Week II
Programs and apps: productivity, graphics, security and other tools
Group 1 Presentation -Planning and Decision Making .pptx
20250228 LYD VKU AI Blended-Learning.pptx
Machine learning based COVID-19 study performance prediction
MIND Revenue Release Quarter 2 2025 Press Release
The Rise and Fall of 3GPP – Time for a Sabbatical?
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation

Hybrid Apps with Qt

  • 1. Qt Hybrid Apps Ynon Perek Tuesday, February 14, 2012
  • 2. Native Is Broken • Deployment is pain • Change is complex for users • Managing versions is a pain for devs Tuesday, February 14, 2012
  • 3. Qt Is Broken • Writing a unique UI is not easy • Can’t reuse code from existing web apps Tuesday, February 14, 2012
  • 4. Hybrid is the new App • Enjoy constant deployment - like a web site • Enjoy unique UI • Enjoy native code Tuesday, February 14, 2012
  • 5. Agenda • Hybrid Architecture • Choosing Hybrid • Bridging The Gap • Tips Tuesday, February 14, 2012
  • 6. Hybrid Arch • Native Qt wrapper acts as a browser • All User Interface and Application HTML/JS/CSS logic is coded in JS • Extra functionality is provided in C++ Qt C++ (Native Code) Tuesday, February 14, 2012
  • 7. Hybrid Code • A special object is inserted to JS from the Qt wrapper application • Calling methods on this object leads to execution of code in C++ • Defaults to single-threaded Tuesday, February 14, 2012
  • 8. Hybrid: When • Flexible or unique UI • Reuse existing web code • Embed dynamic content from the net • Thin Client • An experienced FED on your team Tuesday, February 14, 2012
  • 9. Hybrid: Code • QWebPage is a QObject designed to view and edit web documents • QWebFrame is a QObject representing a frame or iframe in a page • QWebView is a QWidget capable of displaying QWebPage Tuesday, February 14, 2012
  • 10. Demo Display Web Content in a QWebView Tuesday, February 14, 2012
  • 11. Bridging The Gap Use Qt Webkit Bridge to connect web content with native code http://www.flickr.com/photos/groundzero/73471268/ Tuesday, February 14, 2012
  • 12. Accessing QObjects • By default, no QObject is accessible through the web environment • Call QWebFrame’s addToJavaScriptWindowObject to add a QObject Tuesday, February 14, 2012
  • 13. Accessing QObjects // QWebView has a page() method to return // the active QWebPage QWebFrame *frame = myWebPage->mainFrame(); frame->addToJavaScriptWindowObject("someNameForMyObject", myObject); // ... Tuesday, February 14, 2012
  • 14. Invokable Methods class Zombie : public QObject { • All slots in the      Q_OBJECT QObject can public: be invoked      Q_INVOKABLE void eatBrain(); from JS      Q_INVOKABLE int attack();      void rest(); • Can use public slots: Q_INVOKABLE      void walk(QString where); to define an invokable }; method Tuesday, February 14, 2012
  • 15. Demo Call C++ Code From JS Tuesday, February 14, 2012
  • 16. Signal & Slots • Signals & Slots are used to call JS Code from C++ • Define a signal in the QObject • Use connect to bind that signal to a JS function Tuesday, February 14, 2012
  • 17. Signals & Slots class Zombie : public QObject {      Q_OBJECT • Assume Zombie was signals:   void scream(int volume); added to the }; page and named function freeze_in_panic(volume) {    // Oh no it’s the end-of-the-world Zombie } • Arguments Zombie.scream.connect(freeze_in_panic); must match Tuesday, February 14, 2012
  • 18. Passing Data • Arguments are converted when passed between native & web • Failure to match arguments may cause application to crash • Test Everything Tuesday, February 14, 2012
  • 19. Data Types • Numbers • QVariants • Strings • QObjects • Date & Time • Pixmaps & Images • Regular • Web Elements Expressions • Lists • JSON Objects Tuesday, February 14, 2012
  • 20. Numbers • Qt numeric types: int, short, float, double, qreal, qint • JavaScript only has Number • Typedefed numbers are not automatically converted Tuesday, February 14, 2012
  • 21. Strings • JavaScript’s String is easily translated to QString • Using other types in JS will cause the bridge to attempt conversion by calling toString() Tuesday, February 14, 2012
  • 22. Date & Time • Qt has: QDate, QTime & QDateTime • JS has: Date • If JS passed a number to a slot that expected a date, it will be treated as a timestamp Tuesday, February 14, 2012
  • 23. Regular Expressions • JavaScript RegEx objects are translated to QRegExp • Can also pass a string Tuesday, February 14, 2012
  • 24. Lists • If a slot expects a list, and passed an Array, the bridge will try to convert each element. • Use QVariantList to play safe Tuesday, February 14, 2012
  • 25. JSON Objects • A JSON Object translate well to QVariantMap • Use for complex data structures Tuesday, February 14, 2012
  • 26. QVariants & QObjects • It’s possible but not recommended to pass QVariants & QObjects as is • For QObject, pass a pointer to expose functionality • Cannot pass any QObject derived Tuesday, February 14, 2012
  • 27. Pixmaps & Images • A QImage or QPixmap is { converted to a JS width: ..., height: ..., object similar to the toDataURL: right function() { ... }, assignToHTMLImageElement: function(element) { ... } • Can send img } element from web to native Tuesday, February 14, 2012
  • 28. QWebElement • Represents a DOM node inside Qt • Used to write custom renderers or extensions to the environment • Not thread-safe Tuesday, February 14, 2012
  • 29. Demo Passing Data from Qt to JS Tuesday, February 14, 2012
  • 30. Hybrid Tips • Write as little logic as possible in the bridge object • Consider a separate worker thread • Get serious about JavaScript Tuesday, February 14, 2012
  • 31. Thanks For Listening Ynon Perek ynonperek@yahoo.com http://ynonperek.com Tuesday, February 14, 2012