SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
Teaching Native Qt to
Talk Web
by Alan Uthoff
Web API
• RESTful API

• POST 

• GET

• Javascript module

• Ruby module
Useful tools
• Web debugging Proxy (Charles)

• Curl
Qt and Web APIs
• C++ Network model

• Javascript modules in a web view

• QML using XMLHttpRequest
Qt Network Module
•QNetworkRequest

•setRawHeader

•post

•get

•Signal 

•finished(QNetworkReply * reply)

•QNetworkReply

•readAll

•size

•error

•QJsonDocument

•toJson
Curl Example API
$ curl https://api.intercom.io/events 
-X POST 
-H 'Authorization:Bearer <Your access token>' 
-H "Content-Type: application/json" -d'
{
"event_name" : "invited-friend",
"created_at": 1389913941,
"user_id": "314159",
"metadata": {
"invitee_email": "pi@example.org",
"invite_code": "ADDAFRIEND"
}
}'
Example from Intercom Api docs https://developers.intercom.com/reference#events
Qt C++ Example
QJsonDocument json;
json = QJsonDocument::fromVariant(dataMap);
metadata=","metadata":"+json.toJson();
QByteArray timeStamp =
QByteArray::number(QDateTime::currentSecsSinceEpoch());
QByteArray body("{"event_name" :""+ eventName.toUtf8() +”",
"created_at":"+ timeStamp+ ","user_id" :""+user.toUtf8()
+"""+metadata+"}");
QByteArray postDataSize = QByteArray::number(body.size());
QNetworkRequest request ( QUrl::fromUserInput("https://api.intercom.io/
events");
);
QString appString = qApp->applicationDisplayName()+tr(" v”)
+qApp->applicationVersion();
request.setRawHeader("User-Agent",appString.toUtf8());
request.setRawHeader("X-Custom-User-Agent", appString.toUtf8());
request.setRawHeader("Content-Type","application/json");
request.setRawHeader(“Authorization",
QByteArray(m_accessTorken.toStdString().c_str()));
request.setRawHeader("Content-Length", postDataSize);
QNetworkReply reply = m_networkManager.post(request,body);
finished Signal Example
QByteArray response_data = reply->readAll();
int bytesRead = response_data.size();
if(reply->error() == QNetworkReply::NoError)
{
//Note they may not be any on a good reply
if(bytesRead != 0)
{ //process response_data
qInfo()<<response_data;
}
}
else
{
//handle error
if(bytesRead != 0)
{ //handle error with error message in response_data
qWarning()<<response_data;
}
}

reply->deleteLater();
QML Web View with
Javascript
• WebEngineView

• Javascript code from site

• QWebChannel
Web View Example
WebEngineView
{
property bool isLoaded : false
url:"qrc:/index.html"
onLoadingChanged:
{
{
if(loadRequest.status === WebEngineLoadRequest.LoadSucceededStatus)
{
var webcannelString = "new QWebChannel(qt.webChannelTransport,
function(channel) {"
+"var qmlObject = channel.objects.htmlQmlObject;"
+"console.log('calling function'); "
+ "window.Intercom('onShow', function()
{ qmlObject.requestHalfSize(); });"
+ "window.Intercom('onHide', function()
{ qmlObject.requestHelpBubble(); });"
+ ";});"
runJavaScript(qwebchannelJS)
runJavaScript( webcannelString)
isLoaded = true
}
}
Web View Example
Continued
function startIntercom(){
if(isLoaded === true)
{
runJavaScript("window.Intercom('boot', {app_id:
‘dnhfike36’,email:’"+htmlQmlObject.email+"',user_id:'"+htmlQm
lObject.email+"'});");
runJavaScript("window.Intercom('trackEvent',
‘"+eventName+"');");
return true
}
}
}//end of WebEngineView
Web View Example Html
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<titleMy App</title>

<script >Javascript API code Here</script>

</head>

<body></body>

</html>
QML with XMLHttpRequest
• XMLHttpRequest

• onreadystatechange

• responseText

• readyState

• XMLHttpRequest.HEADERS_RECEIVED

• XMLHttpRequest.DONE
Example XMLHttpRequest
function requestLogin(username_To_Use , password_To_Use) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
print('HEADERS_RECEIVED');
}
else if(xhr.readyState === XMLHttpRequest.DONE)
{
if( xhr.status == 200)
{
var object = JSON.parse(xhr.responseText.toString());
if(object["result"] === "okay")
{ print(JSON.stringify(object, null, 2)); }
}
else
{ //error }
}
}
var body = new Object()
body.username = username_To_Use
body.password = password_To_Use
xhr.open("POST", "https://vurhafa2.e1.loginrocket.com/v1/login");
xhr.setRequestHeader("Content-type", "application/json");
xhr.send(JSON.stringify(body));
}
Final Thoughts
• QNetworkRequest

• WebEngineView

• XMLHttpRequest

Más contenido relacionado

La actualidad más candente

OSMC 2011 | Case Study - Icinga at Hyves.nl by Jeffrey Lensen
OSMC 2011 | Case Study - Icinga at Hyves.nl by Jeffrey LensenOSMC 2011 | Case Study - Icinga at Hyves.nl by Jeffrey Lensen
OSMC 2011 | Case Study - Icinga at Hyves.nl by Jeffrey LensenNETWAYS
 
NGSIv2 Overview for Developers That Already Know NGSIv1 20180928
NGSIv2 Overview for Developers That Already Know NGSIv1 20180928NGSIv2 Overview for Developers That Already Know NGSIv1 20180928
NGSIv2 Overview for Developers That Already Know NGSIv1 20180928Fermin Galan
 
Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...
Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...
Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...Fermin Galan
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringJoe Kutner
 
NGSIv2 Overview for Developers That Already Know NGSIv1 20181218
NGSIv2 Overview for Developers That Already Know NGSIv1 20181218NGSIv2 Overview for Developers That Already Know NGSIv1 20181218
NGSIv2 Overview for Developers That Already Know NGSIv1 20181218Fermin Galan
 
Ground Control to Nomad Job Dispatch
Ground Control to Nomad Job DispatchGround Control to Nomad Job Dispatch
Ground Control to Nomad Job DispatchMichael Lange
 
ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214
ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214
ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214Fermin Galan
 
JavaScript - Object-Oriented Programming & Remote Scripting
JavaScript - Object-Oriented Programming & Remote ScriptingJavaScript - Object-Oriented Programming & Remote Scripting
JavaScript - Object-Oriented Programming & Remote ScriptingChen Huang
 
FlutterでGraphQLを扱う
FlutterでGraphQLを扱うFlutterでGraphQLを扱う
FlutterでGraphQLを扱うIgaHironobu
 
Elasticsearch for SQL Users
Elasticsearch for SQL UsersElasticsearch for SQL Users
Elasticsearch for SQL UsersAll Things Open
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul ConnectBram Vogelaar
 
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014Puppet
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stackBram Vogelaar
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet ElasticsearchReal-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet ElasticsearchAlexei Gorobets
 
Apache CouchDB talk at Ontario GNU Linux Fest
Apache CouchDB talk at Ontario GNU Linux FestApache CouchDB talk at Ontario GNU Linux Fest
Apache CouchDB talk at Ontario GNU Linux FestMyles Braithwaite
 
RoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskytingRoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskytingSky Wang
 
4Developers: Michał Papis- Publikowanie gemów
4Developers: Michał Papis- Publikowanie gemów4Developers: Michał Papis- Publikowanie gemów
4Developers: Michał Papis- Publikowanie gemówPROIDEA
 
REST to JavaScript for Better Client-side Development
REST to JavaScript for Better Client-side DevelopmentREST to JavaScript for Better Client-side Development
REST to JavaScript for Better Client-side DevelopmentHyunghun Cho
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache CamelClaus Ibsen
 

La actualidad más candente (20)

OSMC 2011 | Case Study - Icinga at Hyves.nl by Jeffrey Lensen
OSMC 2011 | Case Study - Icinga at Hyves.nl by Jeffrey LensenOSMC 2011 | Case Study - Icinga at Hyves.nl by Jeffrey Lensen
OSMC 2011 | Case Study - Icinga at Hyves.nl by Jeffrey Lensen
 
NGSIv2 Overview for Developers That Already Know NGSIv1 20180928
NGSIv2 Overview for Developers That Already Know NGSIv1 20180928NGSIv2 Overview for Developers That Already Know NGSIv1 20180928
NGSIv2 Overview for Developers That Already Know NGSIv1 20180928
 
Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...
Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...
Orion contextbroker ngs-iv2-overview-for-developers-that-already-know-ngsiv1-...
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and Spring
 
NGSIv2 Overview for Developers That Already Know NGSIv1 20181218
NGSIv2 Overview for Developers That Already Know NGSIv1 20181218NGSIv2 Overview for Developers That Already Know NGSIv1 20181218
NGSIv2 Overview for Developers That Already Know NGSIv1 20181218
 
Ground Control to Nomad Job Dispatch
Ground Control to Nomad Job DispatchGround Control to Nomad Job Dispatch
Ground Control to Nomad Job Dispatch
 
ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214
ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214
ngsiv2-overview-for-developers-that-already-know-ngsiv1-20190214
 
JavaScript - Object-Oriented Programming & Remote Scripting
JavaScript - Object-Oriented Programming & Remote ScriptingJavaScript - Object-Oriented Programming & Remote Scripting
JavaScript - Object-Oriented Programming & Remote Scripting
 
FlutterでGraphQLを扱う
FlutterでGraphQLを扱うFlutterでGraphQLを扱う
FlutterでGraphQLを扱う
 
Elasticsearch for SQL Users
Elasticsearch for SQL UsersElasticsearch for SQL Users
Elasticsearch for SQL Users
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul Connect
 
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
Got Logs? Get Answers with Elasticsearch ELK - PuppetConf 2014
 
Bootstrapping multidc observability stack
Bootstrapping multidc observability stackBootstrapping multidc observability stack
Bootstrapping multidc observability stack
 
Real-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet ElasticsearchReal-time search in Drupal. Meet Elasticsearch
Real-time search in Drupal. Meet Elasticsearch
 
Apache CouchDB talk at Ontario GNU Linux Fest
Apache CouchDB talk at Ontario GNU Linux FestApache CouchDB talk at Ontario GNU Linux Fest
Apache CouchDB talk at Ontario GNU Linux Fest
 
RoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskytingRoR vs-nodejs-by-jcskyting
RoR vs-nodejs-by-jcskyting
 
4Developers: Michał Papis- Publikowanie gemów
4Developers: Michał Papis- Publikowanie gemów4Developers: Michał Papis- Publikowanie gemów
4Developers: Michał Papis- Publikowanie gemów
 
REST to JavaScript for Better Client-side Development
REST to JavaScript for Better Client-side DevelopmentREST to JavaScript for Better Client-side Development
REST to JavaScript for Better Client-side Development
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
Lisp in the Cloud
Lisp in the CloudLisp in the Cloud
Lisp in the Cloud
 

Similar a Teaching Native Qt to Talk Web

API REST et client Javascript - Nuxeo Tour 2014 - Workshop
API REST et client Javascript - Nuxeo Tour 2014 - WorkshopAPI REST et client Javascript - Nuxeo Tour 2014 - Workshop
API REST et client Javascript - Nuxeo Tour 2014 - WorkshopNuxeo
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.Andrey Oleynik
 
Scaling .net containers with event driven workloads
Scaling .net containers with event driven workloadsScaling .net containers with event driven workloads
Scaling .net containers with event driven workloadsNilesh Gule
 
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014Puppet
 
Testing swagger contracts without contract based testing
Testing swagger contracts without contract based testingTesting swagger contracts without contract based testing
Testing swagger contracts without contract based testingАлексей Стягайло
 
Drive chrome(headless) with puppeteer
Drive chrome(headless) with puppeteerDrive chrome(headless) with puppeteer
Drive chrome(headless) with puppeteerVodqaBLR
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEreneechemel
 
REST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD ExampleREST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD ExampleBackand Cohen
 
Android lessons you won't learn in school
Android lessons you won't learn in schoolAndroid lessons you won't learn in school
Android lessons you won't learn in schoolMichael Galpin
 
Should I Make My Own API Gateway?
Should I Make My Own API Gateway?Should I Make My Own API Gateway?
Should I Make My Own API Gateway?Nordic APIs
 
Using Location Data to Showcase Keys, Windows, and Joins in Kafka Streams DSL...
Using Location Data to Showcase Keys, Windows, and Joins in Kafka Streams DSL...Using Location Data to Showcase Keys, Windows, and Joins in Kafka Streams DSL...
Using Location Data to Showcase Keys, Windows, and Joins in Kafka Streams DSL...confluent
 
Event driven autoscaling with KEDA
Event driven autoscaling with KEDAEvent driven autoscaling with KEDA
Event driven autoscaling with KEDANilesh Gule
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationRouven Weßling
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationStuart (Pid) Williams
 
Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHPZoran Jeremic
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedMarcinStachniuk
 
Nick Raienko ''Service-oriented GraphQL''
Nick Raienko ''Service-oriented GraphQL''Nick Raienko ''Service-oriented GraphQL''
Nick Raienko ''Service-oriented GraphQL''OdessaJS Conf
 
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代Shengyou Fan
 

Similar a Teaching Native Qt to Talk Web (20)

API REST et client Javascript - Nuxeo Tour 2014 - Workshop
API REST et client Javascript - Nuxeo Tour 2014 - WorkshopAPI REST et client Javascript - Nuxeo Tour 2014 - Workshop
API REST et client Javascript - Nuxeo Tour 2014 - Workshop
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.
 
About Clack
About ClackAbout Clack
About Clack
 
Scaling .net containers with event driven workloads
Scaling .net containers with event driven workloadsScaling .net containers with event driven workloads
Scaling .net containers with event driven workloads
 
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
 
Testing swagger contracts without contract based testing
Testing swagger contracts without contract based testingTesting swagger contracts without contract based testing
Testing swagger contracts without contract based testing
 
Drive chrome(headless) with puppeteer
Drive chrome(headless) with puppeteerDrive chrome(headless) with puppeteer
Drive chrome(headless) with puppeteer
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
 
REST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD ExampleREST Easy with AngularJS - ng-grid CRUD Example
REST Easy with AngularJS - ng-grid CRUD Example
 
Android lessons you won't learn in school
Android lessons you won't learn in schoolAndroid lessons you won't learn in school
Android lessons you won't learn in school
 
Should I Make My Own API Gateway?
Should I Make My Own API Gateway?Should I Make My Own API Gateway?
Should I Make My Own API Gateway?
 
Using Location Data to Showcase Keys, Windows, and Joins in Kafka Streams DSL...
Using Location Data to Showcase Keys, Windows, and Joins in Kafka Streams DSL...Using Location Data to Showcase Keys, Windows, and Joins in Kafka Streams DSL...
Using Location Data to Showcase Keys, Windows, and Joins in Kafka Streams DSL...
 
Event driven autoscaling with KEDA
Event driven autoscaling with KEDAEvent driven autoscaling with KEDA
Event driven autoscaling with KEDA
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API Documentation
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
 
Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHP
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learned
 
Nick Raienko ''Service-oriented GraphQL''
Nick Raienko ''Service-oriented GraphQL''Nick Raienko ''Service-oriented GraphQL''
Nick Raienko ''Service-oriented GraphQL''
 
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
[JCConf 2020] 用 Kotlin 跨入 Serverless 世代
 

Último

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 

Último (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 

Teaching Native Qt to Talk Web

  • 1. Teaching Native Qt to Talk Web by Alan Uthoff
  • 2. Web API • RESTful API • POST • GET • Javascript module • Ruby module
  • 3. Useful tools • Web debugging Proxy (Charles) • Curl
  • 4. Qt and Web APIs • C++ Network model • Javascript modules in a web view • QML using XMLHttpRequest
  • 5. Qt Network Module •QNetworkRequest •setRawHeader •post •get •Signal •finished(QNetworkReply * reply) •QNetworkReply •readAll •size •error •QJsonDocument •toJson
  • 6. Curl Example API $ curl https://api.intercom.io/events -X POST -H 'Authorization:Bearer <Your access token>' -H "Content-Type: application/json" -d' { "event_name" : "invited-friend", "created_at": 1389913941, "user_id": "314159", "metadata": { "invitee_email": "pi@example.org", "invite_code": "ADDAFRIEND" } }' Example from Intercom Api docs https://developers.intercom.com/reference#events
  • 7. Qt C++ Example QJsonDocument json; json = QJsonDocument::fromVariant(dataMap); metadata=","metadata":"+json.toJson(); QByteArray timeStamp = QByteArray::number(QDateTime::currentSecsSinceEpoch()); QByteArray body("{"event_name" :""+ eventName.toUtf8() +”", "created_at":"+ timeStamp+ ","user_id" :""+user.toUtf8() +"""+metadata+"}"); QByteArray postDataSize = QByteArray::number(body.size()); QNetworkRequest request ( QUrl::fromUserInput("https://api.intercom.io/ events"); ); QString appString = qApp->applicationDisplayName()+tr(" v”) +qApp->applicationVersion(); request.setRawHeader("User-Agent",appString.toUtf8()); request.setRawHeader("X-Custom-User-Agent", appString.toUtf8()); request.setRawHeader("Content-Type","application/json"); request.setRawHeader(“Authorization", QByteArray(m_accessTorken.toStdString().c_str())); request.setRawHeader("Content-Length", postDataSize); QNetworkReply reply = m_networkManager.post(request,body);
  • 8. finished Signal Example QByteArray response_data = reply->readAll(); int bytesRead = response_data.size(); if(reply->error() == QNetworkReply::NoError) { //Note they may not be any on a good reply if(bytesRead != 0) { //process response_data qInfo()<<response_data; } } else { //handle error if(bytesRead != 0) { //handle error with error message in response_data qWarning()<<response_data; } }
 reply->deleteLater();
  • 9. QML Web View with Javascript • WebEngineView • Javascript code from site • QWebChannel
  • 10. Web View Example WebEngineView { property bool isLoaded : false url:"qrc:/index.html" onLoadingChanged: { { if(loadRequest.status === WebEngineLoadRequest.LoadSucceededStatus) { var webcannelString = "new QWebChannel(qt.webChannelTransport, function(channel) {" +"var qmlObject = channel.objects.htmlQmlObject;" +"console.log('calling function'); " + "window.Intercom('onShow', function() { qmlObject.requestHalfSize(); });" + "window.Intercom('onHide', function() { qmlObject.requestHelpBubble(); });" + ";});" runJavaScript(qwebchannelJS) runJavaScript( webcannelString) isLoaded = true } }
  • 11. Web View Example Continued function startIntercom(){ if(isLoaded === true) { runJavaScript("window.Intercom('boot', {app_id: ‘dnhfike36’,email:’"+htmlQmlObject.email+"',user_id:'"+htmlQm lObject.email+"'});"); runJavaScript("window.Intercom('trackEvent', ‘"+eventName+"');"); return true } } }//end of WebEngineView
  • 12. Web View Example Html <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <titleMy App</title> <script >Javascript API code Here</script> </head> <body></body> </html>
  • 13. QML with XMLHttpRequest • XMLHttpRequest • onreadystatechange • responseText • readyState • XMLHttpRequest.HEADERS_RECEIVED • XMLHttpRequest.DONE
  • 14. Example XMLHttpRequest function requestLogin(username_To_Use , password_To_Use) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) { print('HEADERS_RECEIVED'); } else if(xhr.readyState === XMLHttpRequest.DONE) { if( xhr.status == 200) { var object = JSON.parse(xhr.responseText.toString()); if(object["result"] === "okay") { print(JSON.stringify(object, null, 2)); } } else { //error } } } var body = new Object() body.username = username_To_Use body.password = password_To_Use xhr.open("POST", "https://vurhafa2.e1.loginrocket.com/v1/login"); xhr.setRequestHeader("Content-type", "application/json"); xhr.send(JSON.stringify(body)); }
  • 15. Final Thoughts • QNetworkRequest • WebEngineView • XMLHttpRequest