SlideShare a Scribd company logo
1 of 26
Download to read offline
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

What's hot

Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010
Chris Ramsdale
 
Vaadin7 modern-web-apps-in-java
Vaadin7 modern-web-apps-in-javaVaadin7 modern-web-apps-in-java
Vaadin7 modern-web-apps-in-java
Joonas Lehtinen
 
Using Grails to power your electric car
Using Grails to power your electric carUsing Grails to power your electric car
Using Grails to power your electric car
Marco Pas
 

What's hot (19)

Vaadin7
Vaadin7Vaadin7
Vaadin7
 
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...
 
My way to clean android v2 English DroidCon Spain
My way to clean android v2 English DroidCon SpainMy way to clean android v2 English DroidCon Spain
My way to clean android v2 English DroidCon Spain
 
Android development
Android developmentAndroid development
Android development
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010
 
Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
 
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
 
Meet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIMeet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UI
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
The Next Step in AS3 Framework Evolution
The Next Step in AS3 Framework EvolutionThe Next Step in AS3 Framework Evolution
The Next Step in AS3 Framework Evolution
 
My way to clean android V2
My way to clean android V2My way to clean android V2
My way to clean android V2
 
Google Developer Fest 2010
Google Developer Fest 2010Google Developer Fest 2010
Google Developer Fest 2010
 
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API AuthorizationGDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
GDG Cloud Taipei: Meetup #52 - Istio Security: API Authorization
 
Vaadin7 modern-web-apps-in-java
Vaadin7 modern-web-apps-in-javaVaadin7 modern-web-apps-in-java
Vaadin7 modern-web-apps-in-java
 
Intro
IntroIntro
Intro
 
Using Grails to power your electric car
Using Grails to power your electric carUsing Grails to power your electric car
Using Grails to power your electric car
 
State of the Art OpenGL and Qt
State of the Art OpenGL and QtState of the Art OpenGL and Qt
State of the Art OpenGL and Qt
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret Sauce
 
[JEEConf-2017] RxJava as a key component in mature Big Data product
[JEEConf-2017] RxJava as a key component in mature Big Data product[JEEConf-2017] RxJava as a key component in mature Big Data product
[JEEConf-2017] RxJava as a key component in mature Big Data product
 

Viewers also liked

Viewers also liked (7)

WebKit Security Updates (GUADEC 2016)
WebKit Security Updates (GUADEC 2016)WebKit Security Updates (GUADEC 2016)
WebKit Security Updates (GUADEC 2016)
 
Googleツールを使いこなして世界中の仲間と楽しく仕事を進めよう【初心者向け】
Googleツールを使いこなして世界中の仲間と楽しく仕事を進めよう【初心者向け】Googleツールを使いこなして世界中の仲間と楽しく仕事を進めよう【初心者向け】
Googleツールを使いこなして世界中の仲間と楽しく仕事を進めよう【初心者向け】
 
Fontconfigことはじめ
FontconfigことはじめFontconfigことはじめ
Fontconfigことはじめ
 
Chromium on Wayland Desktop (BlinkOn 7)
Chromium on Wayland Desktop (BlinkOn 7)Chromium on Wayland Desktop (BlinkOn 7)
Chromium on Wayland Desktop (BlinkOn 7)
 
Compiling and Optimizing Your Own Browser with WebKit
Compiling and Optimizing Your Own Browser with WebKitCompiling and Optimizing Your Own Browser with WebKit
Compiling and Optimizing Your Own Browser with WebKit
 
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 ...
 
Taller: Licencias de Software Libre
Taller: Licencias de Software LibreTaller: Licencias de Software Libre
Taller: Licencias de Software Libre
 

Similar to Qt & Webkit

Hybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKitHybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKit
Ariya Hidayat
 
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Василевский Илья (Fun-box): "автоматизация браузера при помощи PhantomJS"
Provectus
 
Google io bootcamp_2010
Google io bootcamp_2010Google io bootcamp_2010
Google io bootcamp_2010
Chris Ramsdale
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9
Shih-Hsiang Lin
 

Similar to Qt & Webkit (20)

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

More from QT-day

More from QT-day (12)

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

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

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