SlideShare a Scribd company logo
Hybrid development
  using Qt WebKit
  http://src.develer.com/gitweb/pub/users/th30z/qtday/.git

   git clone git://src.develer.com/users/th30z/qtday/.git
WebKit

WebKit is an open source
web browser engine.
   state of the art rendering
    engine
   css/svg support
   super fast js engine
   plugin support
WebKit Everywhere
Components of WebKit

            CSS
      DOM          SVG
 HTML                        Canvas
         WebCore
   Rendering
                  JavaScriptCore
                    Worker            Storage
WebKit Library                Sockets
Different Ports
                            WebCore Graphics


Graphics
Context
                 Chromium             Gtk
           Mac                 Qt

                     Skia           Cairo
     Core Graphics          QtPainter

                                     Graphics
                                      Stack
QtWebKit
    A bridge between Qt and WebKit
With QtWebKit you can:
●   (easily!) embed a fully
    functional, standard
    compliant, web browser
    inside your application
●   inspect/extract the
    content
●   manipulate the web page
●   integrate your application
    with web services
QtWebKit (main) modules
   QWebView
          a QWidget (your browser window/tab)
   QWebPage
          a browsing session: settings + history + plugin +
             network + user interaction + document
   QWebFrame
          the document, one QWebFrame per html page or
             svg document.
          can have additional child frame (one per
             <frame>)
          magic happens here (qt ↔ page interaction)
QWebView
   QWebView is your “browser”
   QWebView is a QWidget
   QWebView exposes high-level signals/slots
           load() / reload() / stop()
           back() / forward()
           linkClicked() / loadProgress() /
               statusBarMessage()
   QWebView signals/slots are an excerpt of QWebPage +
    QWebFrame
QWebPage
   QWebPage is not a QWidget
           but a QApplication is still required
   QWebPage is the browsing ecosystem
           history + settings + plugins + network +
              document
   Interact with the document via the PageAction
QWebFrame
   QWebFrame is not a QWidget
   QWebFrame is a frame inside a web page
   each QWebPage object has at least one frame
           plus one QWebFrame for every <frame />
Using QWebView
#include <QtGui/QApplication>
#include <QWebView>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWebView w;
    w.load(QUrl("http://www.google.com/"));
    w.show();
    return a.exec();
}
Content via String



QWebView webView;
webView.setContent(“<body>Hello World</body>”));
webView.show();
Capture to Image
QWebPage page;
…

QImage image(size, QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::transparent);

QPainter p(&image);
page.mainFrame()->render(&p);
p.end();

image.save(fileName);
Qt & JavaScript

   eval javascript code inside the frame context
            QWebFrame::evaluateJavaScript
   inject a QObject into the frame context
Exposing to the World
                                                      Object Instance
                                                  From Qt/C++ to Javascript
                                  Variable name
                        Visible from JavaScript

 QWebFrame::addToJavaScriptWindowObject(QString, QObject *)


                                                             Exported

                                             Public Slots
QWebView w;
w.page()->mainFrame()                      Public Properties
                                                Signals
Exposing to the World
class Dialog : public QDialog {
   Q_OBJECT                                       Public Slots
     public:
                                                Public Properties
       Dialog (QObject *parent = 0);                 Signals
     public slots:
       void showMessage (const QString& message);
};



     QWebView webView;
     QWebFrame *frame = webView.page()->mainFrame();
     frame->addToJavaScriptWindowObject(“dialog”, new Dialog);
Exposing to the World


page()->mainFrame()->addToJavaScriptWindowObject(“dialog”, new Dialog);


      <input type=”button” value=”Click Me!”
          onClick=”dialog.showMessage(‘You clicked me!’)”>


                                           Public Slot
              Instance of
             Dialog Object
Signal & Slot
                        Javascript




           Signal           Slot
foobar.modified.connect(doSomething)


QObject                  JavaScript
Instance                  Function
Triggering Actions
class StopWatch : public QObject {
 Q_OBJECT                                 StopWatch::StopWatch (QObject *parent)
                                            : QObject(parent), m_tick(0)
 public:                                  {
  StopWatch (QObject *parent = 0);          QTimer *timer = new QTimer(this);
                                            timer->setInterval(1000);
 signals:                                   connect(timer, SIGNAL(timeout()),
  void tick (int t);                                this, SLOT(update()));
                                            timer->start();
 private slots:                           }
  void update();
                                          void StopWatch::update() {
 private:                                   emit tick(m_tick++);
   int m_tick;                            }
};

page->mainFrame()->addToJavaScriptWindowObject(“stopWatch”, new StopWatch);
                                 <script>
                                 stopWatch.tick.connect(function(t) {
                                    document.getElementById(‘tick’).innerText = t;
                                 });
                                 </script>
Coming back to Native

                                        JavaScript Code


    QVariant QWebFrame::evaluateJavaScript(QString)



  mostly key-value pair
(like JavaScript Objects)
       QMap
Coming back to Native
function getJsFuncMapValue() {     QVariant res;
   return {
      'test-list': [10, 20, 30],   res = frame->evaluateJavaScript("getJsFuncMapValue()");
      'test-string': "Hello",      QMap<QString, QVariant> resMap = res.toMap();
      'test-int': 20               QList<QVariant> resList = resMap[“test-list”].toList();
   }                               QString resString = resMap[“test-string”].toString();
}                                  int resInt = resMap[“test-int”].toInt();

function getJsFuncListValue() {
   return [40, 50, 60];            res = frame->evaluateJavaScript("getJsFuncListValue()");
}                                  QList<QVariant> resList = res.toList();

function getJsFuncIntValue(a) {
   return 80 + a;                  res = frame->evaluateJavaScript(“getJsFuncIntValue(2)”);
}                                  int resInt = res.toInt();
Maps Example
                 Javascript



     <script type="text/javascript">
     var map = null;
     window.onload = function() {
       map = new ovi.mapsapi.map.Display(
          document.getElementById("map"), {
             'zoomLevel': 12,
             'center': [43.779571,11.23726]
          }
       );
     }
     </script>
Maps Example
                                                                          QtWebKit
class MapView : public QWebView {
   ...
   MapView(QWidget *parent = 0) : QWebView(parent) {
       load(QUrl("maps.html"));
   }

     void moveTo (float lon, float lat) {
       QString js = QString("map.setCenter([%1, %2], true)").arg(lon).arg(lat);
       page()->mainFrame()->evaluateJavaScript(js);
     }

     void setZoomLevel (int level) {
       QString js = QString("map.setZoomLevel(%1, true)").arg(level);
       page()->mainFrame()->evaluateJavaScript(js);
     }
     …
};
                                                        MapView mapView;
                                                        mapView.moveTo(57.772232, 94.833984);
                                                        mapView.setType(MapView::Satellite);
                                                        mapView.setZoomLevel(6);
Hybrid Applications Qt + WebKit
   You can inject a QObject
           Call Public Slots
           Set/Get Public Properties
           Connect a signal to a javascript function
   Or you can extract from the frame context a function
    and call it from the C++ side.




                                 http://src.develer.com/gitweb/pub/users/th30z/qtday/.git

                                  git clone git://src.develer.com/users/th30z/qtday/.git
Questions?
 Hybrid development
   using Qt WebKit




           http://src.develer.com/gitweb/pub/users/th30z/qtday/.git

            git clone git://src.develer.com/users/th30z/qtday/.git


                                                                      25
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
Hybrid Apps (Native + Web) using WebKit
PDF
Vaadin 7 Today and Tomorrow
PDF
Qt and QML performance tips & tricks for Qt 4.7
PPTX
Testing microservices: Tools and Frameworks
PDF
QThreads: Are You Using Them Wrong?
 
PDF
Vaadin today and tomorrow
PPTX
Mvp - типичные задачи и способ их решения в Moxy
PDF
Sustaining Test-Driven Development
Hybrid Apps (Native + Web) using WebKit
Vaadin 7 Today and Tomorrow
Qt and QML performance tips & tricks for Qt 4.7
Testing microservices: Tools and Frameworks
QThreads: Are You Using Them Wrong?
 
Vaadin today and tomorrow
Mvp - типичные задачи и способ их решения в Moxy
Sustaining Test-Driven Development

What's hot (19)

PDF
PPTX
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
PDF
My way to clean android v2 English DroidCon Spain
PDF
Android development
ZIP
Building Web Apps Sanely - EclipseCon 2010
PDF
Qt Widget In-Depth
PDF
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
PDF
Meet the Widgets: Another Way to Implement UI
 
ODP
Qt Workshop
ODP
The Next Step in AS3 Framework Evolution
PDF
My way to clean android V2
ZIP
Google Developer Fest 2010
PDF
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
PDF
Vaadin7 modern-web-apps-in-java
PPT
Intro
ODP
Using Grails to power your electric car
PDF
State of the Art OpenGL and Qt
 
PDF
Hiveminder - Everything but the Secret Sauce
PDF
[JEEConf-2017] RxJava as a key component in mature Big Data product
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
My way to clean android v2 English DroidCon Spain
Android development
Building Web Apps Sanely - EclipseCon 2010
Qt Widget In-Depth
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
Meet the Widgets: Another Way to Implement UI
 
Qt Workshop
The Next Step in AS3 Framework Evolution
My way to clean android V2
Google Developer Fest 2010
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
Vaadin7 modern-web-apps-in-java
Intro
Using Grails to power your electric car
State of the Art OpenGL and Qt
 
Hiveminder - Everything but the Secret Sauce
[JEEConf-2017] RxJava as a key component in mature Big Data product
Ad

Viewers also liked (7)

PDF
WebKit Security Updates (GUADEC 2016)
PPTX
Googleツールを使いこなして世界中の仲間と楽しく仕事を進めよう【初心者向け】
PPTX
Fontconfigことはじめ
PDF
Chromium on Wayland Desktop (BlinkOn 7)
PDF
Compiling and Optimizing Your Own Browser with WebKit
PDF
A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...
PDF
Taller: Licencias de Software Libre
WebKit Security Updates (GUADEC 2016)
Googleツールを使いこなして世界中の仲間と楽しく仕事を進めよう【初心者向け】
Fontconfigことはじめ
Chromium on Wayland Desktop (BlinkOn 7)
Compiling and Optimizing Your Own Browser with WebKit
A Browser for the Automotive: Introduction to WebKit for Wayland (Automotive ...
Taller: Licencias de Software Libre
Ad

Similar to Qt & Webkit (20)

PDF
Hybrid Apps (Native + Web) using WebKit
PDF
Hybrid Apps (Native + Web) via QtWebKit
PDF
Petri Niemi Qt Web Kit
PDF
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
PPT
Gwt RPC
PPT
Google Web Toolkit
ODP
Treinamento Qt básico - aula II
KEY
JBoss World 2010
PDF
Vaadin 7 CN
PDF
Workshop: Building Vaadin add-ons
KEY
New Design of OneRing
PDF
03 - Qt UI Development
PDF
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
KEY
Google io bootcamp_2010
KEY
PDF
Gdg dev fest hybrid apps your own mini-cordova
PDF
Best Practices in Qt Quick/QML - Part III
 
PPT
Google Web Toolkits
PDF
Google Web Toolkit
PDF
[C++ gui programming with qt4] chap9
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) via QtWebKit
Petri Niemi Qt Web Kit
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Gwt RPC
Google Web Toolkit
Treinamento Qt básico - aula II
JBoss World 2010
Vaadin 7 CN
Workshop: Building Vaadin add-ons
New Design of OneRing
03 - Qt UI Development
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
Google io bootcamp_2010
Gdg dev fest hybrid apps your own mini-cordova
Best Practices in Qt Quick/QML - Part III
 
Google Web Toolkits
Google Web Toolkit
[C++ gui programming with qt4] chap9

More from QT-day (12)

PPTX
EBV e Freescale: cosa possono fare per lo sviluppo delle vostre applicazioni ...
ODP
Qt Networking avanzato
ODP
Qt Concurrent
ODP
Qt Creator, l'arma segreta!
ODP
Internazionalizza le tue applicazioni
ODP
Home automation con BTicino MyHome
PPTX
EBV e Freescale: cosa possono fare per lo sviluppo delle vostre applicazioni ...
PDF
Welcome - Introduzione - Burkhard Stubert
PDF
Contribuire al Qt Project
PDF
Qt Platform Abstraction
PDF
Qtday Introduzione a qt quick
PDF
Develer offering for Qt
EBV e Freescale: cosa possono fare per lo sviluppo delle vostre applicazioni ...
Qt Networking avanzato
Qt Concurrent
Qt Creator, l'arma segreta!
Internazionalizza le tue applicazioni
Home automation con BTicino MyHome
EBV e Freescale: cosa possono fare per lo sviluppo delle vostre applicazioni ...
Welcome - Introduzione - Burkhard Stubert
Contribuire al Qt Project
Qt Platform Abstraction
Qtday Introduzione a qt quick
Develer offering for Qt

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
sap open course for s4hana steps from ECC to s4
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Empathic Computing: Creating Shared Understanding
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

Qt & Webkit

  • 1. Hybrid development using Qt WebKit http://src.develer.com/gitweb/pub/users/th30z/qtday/.git git clone git://src.develer.com/users/th30z/qtday/.git
  • 2. WebKit WebKit is an open source web browser engine.  state of the art rendering engine  css/svg support  super fast js engine  plugin support
  • 4. Components of WebKit CSS DOM SVG HTML Canvas WebCore Rendering JavaScriptCore Worker Storage WebKit Library Sockets
  • 5. Different Ports WebCore Graphics Graphics Context Chromium Gtk Mac Qt Skia Cairo Core Graphics QtPainter Graphics Stack
  • 6. QtWebKit A bridge between Qt and WebKit With QtWebKit you can: ● (easily!) embed a fully functional, standard compliant, web browser inside your application ● inspect/extract the content ● manipulate the web page ● integrate your application with web services
  • 7. QtWebKit (main) modules  QWebView  a QWidget (your browser window/tab)  QWebPage  a browsing session: settings + history + plugin + network + user interaction + document  QWebFrame  the document, one QWebFrame per html page or svg document.  can have additional child frame (one per <frame>)  magic happens here (qt ↔ page interaction)
  • 8. QWebView  QWebView is your “browser”  QWebView is a QWidget  QWebView exposes high-level signals/slots  load() / reload() / stop()  back() / forward()  linkClicked() / loadProgress() / statusBarMessage()  QWebView signals/slots are an excerpt of QWebPage + QWebFrame
  • 9. QWebPage  QWebPage is not a QWidget  but a QApplication is still required  QWebPage is the browsing ecosystem  history + settings + plugins + network + document  Interact with the document via the PageAction
  • 10. QWebFrame  QWebFrame is not a QWidget  QWebFrame is a frame inside a web page  each QWebPage object has at least one frame  plus one QWebFrame for every <frame />
  • 12. Content via String QWebView webView; webView.setContent(“<body>Hello World</body>”)); webView.show();
  • 13. Capture to Image QWebPage page; … QImage image(size, QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); QPainter p(&image); page.mainFrame()->render(&p); p.end(); image.save(fileName);
  • 14. Qt & JavaScript  eval javascript code inside the frame context  QWebFrame::evaluateJavaScript  inject a QObject into the frame context
  • 15. Exposing to the World Object Instance From Qt/C++ to Javascript Variable name Visible from JavaScript QWebFrame::addToJavaScriptWindowObject(QString, QObject *) Exported Public Slots QWebView w; w.page()->mainFrame() Public Properties Signals
  • 16. Exposing to the World class Dialog : public QDialog { Q_OBJECT Public Slots public: Public Properties Dialog (QObject *parent = 0); Signals public slots: void showMessage (const QString& message); }; QWebView webView; QWebFrame *frame = webView.page()->mainFrame(); frame->addToJavaScriptWindowObject(“dialog”, new Dialog);
  • 17. Exposing to the World page()->mainFrame()->addToJavaScriptWindowObject(“dialog”, new Dialog); <input type=”button” value=”Click Me!” onClick=”dialog.showMessage(‘You clicked me!’)”> Public Slot Instance of Dialog Object
  • 18. Signal & Slot Javascript Signal Slot foobar.modified.connect(doSomething) QObject JavaScript Instance Function
  • 19. Triggering Actions class StopWatch : public QObject { Q_OBJECT StopWatch::StopWatch (QObject *parent) : QObject(parent), m_tick(0) public: { StopWatch (QObject *parent = 0); QTimer *timer = new QTimer(this); timer->setInterval(1000); signals: connect(timer, SIGNAL(timeout()), void tick (int t); this, SLOT(update())); timer->start(); private slots: } void update(); void StopWatch::update() { private: emit tick(m_tick++); int m_tick; } }; page->mainFrame()->addToJavaScriptWindowObject(“stopWatch”, new StopWatch); <script> stopWatch.tick.connect(function(t) { document.getElementById(‘tick’).innerText = t; }); </script>
  • 20. Coming back to Native JavaScript Code QVariant QWebFrame::evaluateJavaScript(QString) mostly key-value pair (like JavaScript Objects) QMap
  • 21. Coming back to Native function getJsFuncMapValue() { QVariant res; return { 'test-list': [10, 20, 30], res = frame->evaluateJavaScript("getJsFuncMapValue()"); 'test-string': "Hello", QMap<QString, QVariant> resMap = res.toMap(); 'test-int': 20 QList<QVariant> resList = resMap[“test-list”].toList(); } QString resString = resMap[“test-string”].toString(); } int resInt = resMap[“test-int”].toInt(); function getJsFuncListValue() { return [40, 50, 60]; res = frame->evaluateJavaScript("getJsFuncListValue()"); } QList<QVariant> resList = res.toList(); function getJsFuncIntValue(a) { return 80 + a; res = frame->evaluateJavaScript(“getJsFuncIntValue(2)”); } int resInt = res.toInt();
  • 22. Maps Example Javascript <script type="text/javascript"> var map = null; window.onload = function() { map = new ovi.mapsapi.map.Display( document.getElementById("map"), { 'zoomLevel': 12, 'center': [43.779571,11.23726] } ); } </script>
  • 23. Maps Example QtWebKit class MapView : public QWebView { ... MapView(QWidget *parent = 0) : QWebView(parent) { load(QUrl("maps.html")); } void moveTo (float lon, float lat) { QString js = QString("map.setCenter([%1, %2], true)").arg(lon).arg(lat); page()->mainFrame()->evaluateJavaScript(js); } void setZoomLevel (int level) { QString js = QString("map.setZoomLevel(%1, true)").arg(level); page()->mainFrame()->evaluateJavaScript(js); } … }; MapView mapView; mapView.moveTo(57.772232, 94.833984); mapView.setType(MapView::Satellite); mapView.setZoomLevel(6);
  • 24. Hybrid Applications Qt + WebKit  You can inject a QObject  Call Public Slots  Set/Get Public Properties  Connect a signal to a javascript function  Or you can extract from the frame context a function and call it from the C++ side. http://src.develer.com/gitweb/pub/users/th30z/qtday/.git git clone git://src.develer.com/users/th30z/qtday/.git
  • 25. Questions? Hybrid development using Qt WebKit http://src.develer.com/gitweb/pub/users/th30z/qtday/.git git clone git://src.develer.com/users/th30z/qtday/.git 25
  • 26. 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