Teaching Native Qt to Talk Web: by Alan Uthoff
Integrating native applications with web frameworks is a must for all modern applications. However, not all frameworks have a native SDKs. Learn how to interface with Web API when there is no native SDK using the robust Qt framework in C++ and QML.
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
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>