Qt Features for Hybrid Web/Native Application Development



Similar documents
Research on HTML5 in Web Development

Beginning Nokia Apps. Development. Qt and HTIVIL5 for Symbian and MeeGo. Ray Rischpater. Apress. Daniel Zucker

This document will describe how you can create your own, fully responsive. drag and drop template to use in the creator.

IE Class Web Design Curriculum

Short notes on webpage programming languages

INTERNET PROGRAMMING AND DEVELOPMENT AEC LEA.BN Course Descriptions & Outcome Competency

Portals and Hosted Files

Example. Represent this as XML

Web Design Specialist

Mobile Learning Application Based On Hybrid Mobile Application Technology Running On Android Smartphone and Blackberry

HTML5 the new. standard for Interactive Web

Outline. CIW Web Design Specialist. Course Content

Building A Very Simple Web Site

WP Popup Magic User Guide

Web Design Technology

AUTOMATED CONFERENCE CD-ROM BUILDER AN OPEN SOURCE APPROACH Stefan Karastanev

Developing Offline Web Application

IBM Unica emessage Version 8 Release 6 February 13, User's Guide

Oracle Portal and Accessibility Requirements

Tizen Web Runtime Update. Ming Jin Samsung Electronics

jquery Tutorial for Beginners: Nothing But the Goods

Working With Templates in Web Publisher. Contributed by Paul O Mahony Developer Program

Using WINK to create custom animated tutorials

Kentico CMS Web Parts

Interspire Website Publisher Developer Documentation. Template Customization Guide

An Oracle White Paper May Creating Custom PDF Reports with Oracle Application Express and the APEX Listener

Terminal 4 Site Manager User Guide. Need help? Call the ITD Lab, x7471

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

ebooks: Exporting EPUB files from Adobe InDesign

Data Transfer Tips and Techniques

ADOBE DREAMWEAVER CS3 DESIGN, DEVELOP, AND MAINTAIN STANDARDS-BASED WEBSITES AND APPLICATIONS

4 Understanding. Web Applications IN THIS CHAPTER. 4.1 Understand Web page development. 4.2 Understand Microsoft ASP.NET Web application development

We automatically generate the HTML for this as seen below. Provide the above components for the teaser.txt file.

Elgg 1.8 Social Networking

Development Techniques for Native/Hybrid Tizen Apps. Presenter Matti Pakarinen

JISIS and Web Technologies

WHAT'S NEW IN SHAREPOINT 2013 WEB CONTENT MANAGEMENT

JavaFX Session Agenda

Drupal CMS for marketing sites

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

Implementing a Web-based Transportation Data Management System

McAfee Web Gateway Administration Intel Security Education Services Administration Course Training

Web Designing with UI Designing

Use your mobile phone as Modem loading Videos

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Joomla! template Blendvision v 1.0 Customization Manual

DIPLOMA IN WEBDEVELOPMENT

PDG Software. Site Design Guide

Visualizing a Neo4j Graph Database with KeyLines

MASTERTAG DEVELOPER GUIDE

WP Popup Magic User Guide

WIX: Building a Website with a Template. Choosing a Template First you will need to choose a template from the Create section of the Wix website.

Development of Content Management System with Animated Graph

Web Design and Development Program (WDD)

Basic tutorial for Dreamweaver CS5

Dreamweaver Tutorial - Dreamweaver Interface

English. Asema.com Portlets Programmers' Manual

RSS Feeds - Content Syndication Feed2JS: a simple solution to display RSS feeds

Voluntary Product Accessibility Template Blackboard Learn Release 9.1 April 2014 (Published April 30, 2014)

The Smart Forms Web Part allows you to quickly add new forms to SharePoint pages, here s how:

FileMaker 13. WebDirect Guide

Sage CRM. Sage CRM 7.3 Mobile Guide

Programming in HTML5 with JavaScript and CSS3

Pastiche. Bring training content to your learners tablets PASTICHE DATA SHEET. Product Highlights

ECG-1615A. How to Integrate IBM Enterprise Content Management Solutions With Microsoft SharePoint and IBM Connections. elinar.com

Salesforce Customer Portal Implementation Guide

Microsoft Publisher 2010 What s New!

Introducing our new Editor: Creator

Dreamweaver CS3 THE MISSING MANUAL. David Sawyer McFarland. POGUE PRESS" O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

SNM Content-Editor. Magento Extension. Magento - Extension. Professional Edition (V1.2.1) Browse & Edit. Trust only what you really sees.

SUBJECT CODE : 4074 PERIODS/WEEK : 4 PERIODS/ SEMESTER : 72 CREDIT : 4 TIME SCHEDULE UNIT TOPIC PERIODS 1. INTERNET FUNDAMENTALS & HTML Test 1

Chapter 12: Advanced topic Web 2.0

Create stunning flash movies online in minutes with the easiest flash maker in the world! Try the world's best online flash movie maker.

Inspiring Creative Fun Ysbrydoledig Creadigol Hwyl. Web Design in Nvu Workbook 1

Content Author's Reference and Cookbook

601/8498/X IAO Level 3 Certificate in Web Design and Development (RQF)

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Taleo Enterprise. Career Section Branding Definition. Version 7.5

WEB, HYBRID, NATIVE EXPLAINED CRAIG ISAKSON. June 2013 MOBILE ENGINEERING LEAD / SOFTWARE ENGINEER

A Web- based Approach to Music Library Management. Jason Young California Polytechnic State University, San Luis Obispo June 3, 2012

Creating Web Pages with Microsoft FrontPage

An Overview of Oracle Forms Server Architecture. An Oracle Technical White Paper April 2000

OpenIMS 4.2. Document Management Server. User manual

ETPL Extract, Transform, Predict and Load

A set-up guide and general information to help you get the most out of your new theme.

Course Scheduling Support System

The document may be freely distributed in its entirety, either digitally or in printed format, to all EPiServer Mail users.

Gateway Apps - Security Summary SECURITY SUMMARY

What's New in BarTender 2016

Mobile App Infrastructure for Cross-Platform Deployment (N11-38)

<Insert Picture Here> Oracle Application Express 4.0

Index. Page 1. Index

OPENTABLE GROUP SEARCH MODULE GETTING STARTED ADD RESERVATIONS TO YOUR WEBSITE

Transcription:

White Paper Qt Features for Hybrid Web/Native Application Development Today s computer users live and work in an interconnected world. They always have a network at hand and expect their data to be available at all times wherever they are. The boundary between desktop applications and the web is closing and hybrid applications, mixing the best of both worlds, are starting to emerge. With the Qt WebKit Integration and the QtNetwork module, you have all the tools that you need to create your own hybrid applications by mixing JavaScript, style sheets, web content and Qt components freely. Combined with the QtXmlPatterns module, you can download, transform and query XML and present it in a hybrid web environment. This paper presents the features provided in the Qt WebKit Integration, and discusses how you can use them to develop hybrid applications.

Qt Features for Hybrid Web/Native Application Development Today's computer users live and work in an interconnected world. They always have a network at hand and expect their data to be available at all times wherever they are. The boundary between desktop applications and the web is closing and hybrid applications, mixing the best of both worlds, are starting to emerge. With the Qt WebKit Integration and the QtNetwork module, you have all the tools that you need to create your own hybrid applications by mixing JavaScript, style sheets, web content and Qt components freely. Combined with the QtXmlPatterns module, you can download, transform and query XML and present it in a hybrid web environment. Features of the Qt WebKit Integration One of the key components when mixing web and native applications is the web contents rendering engine QtWebKit. This module makes it easy to integrate the wide-spread WebKit engine into your applications. The integration includes triggering JavaScript from C++, as well as integrating C++ objects into a web page and interacting with those objects through JavaScript. The WebKit engine can be seen as a fully fledged web browser engine. The highlights of this engine are its modern rendering features: ACID3 compliance gives you proper standards-compliant rendering. CSS-based transformations makes it possible to scale, rotate, skew and translate page elements through CSS. CSS-based animations let you make smooth transitions between different states. For instance, elements can be made to fade in and out as the mouse cursor hovers over them. Support for the video-tag allows for embedding video contents easily. The video player uses codecs available from the Phonon Multimedia framework (also a part of Qt). Full page zooming makes it possible to scale not only the font size, but the entire page including images. NPAPI support to embed standard web browser plugins enabling third party media and more. The SquirrelFish JavaScript engine offers one of the fastest JavaScript experiences available. A modern, capable HTML rendering engine is only one half of a hybrid application. The other half is the interaction between the native application and the rendered contents. The Qt WebKit integration offers all the pieces of such a puzzle. Embed Qt widgets into a web page using the object-tag. This lets your web page contain Qt widgets along with native C++ code as part of the visual appearance of the page. Access Qt objects from the JavaScript. This allows you to insert C++ objects into the JavaScript context, letting the web page's script interact directly with your data structures. 2008 Nokia Corporation and/or its subsidiaries. Qt Features for Hybrid Web/Native Application Development 1

Trigger JavaScript from Qt. You can call JavaScript functions in their web page context from your C++ code and trigger events in the web page. Shared client side storage. This gives you access to a database accessible both from JavaScript and C++, making it possible to share large amounts of data easily even when offline. The Qt WebKit integration forms the base of all hybrid applications, but the key factor is getting the native code and web contents to interact. Qt offers a number of techniques to interconnect the two worlds, sharing events and data while sharing the screen as one homogeneous interface to the user. Interacting With Embedded Qt Objects There are two ways to embed Qt objects into a web page illustrated using the QWebView widget. You can either add your objects to the JavaScript context of a page, or you can create a plugin that makes it possible to place Qt widgets inside a web page using the object tag. The latter is an easy way to start creating a hybrid application: simply put your widgets inside a web page. When the widgets are in the page, their public slots will be exposed to JavaScript functions of the page as ordinary functions. To add a widget to a page, you need to tell your QWebPage object that the widget is available. This is done by subclassing the QWebPluginFactory class and reimplementing the methods plugins and create. The plugins method informs the web page of which plugins it makes available, while the create method creates widgets on demand. From the HTML making up the web page in question, the widgets are created using the object tag. For instance, the following tag will attempt to create an instance of an application/x-qt-colorlabel widget. <object type="application/x-qt-colorlabel" width="50px" height="20px" id="label" /> To facilitate the creation of such a widget, we must enable plugins and tell QWebPage about the plugin factory class. In the code below, the ColorLabelFactory creates instances of ColorLabel widgets in in response to application/x-qt-colorlabel requests. {... QWebSettings::globalSettings()-> setattribute( QWebSettings::PluginsEnabled, true ); webview->page()->setpluginfactory( new ColorLabelFactory( this ) );... } 2008 Nokia Corporation and/or its subsidiaries. Qt Features for Hybrid Web/Native Application Development 2

The ColorLabel widget exposes a public slot called changecolor(). This is automatically made available to JavaScript in the web page. Adding a link to the HTML referring to the element makes it possible to activate C++ functions in a simple way. <a href='javascript:document.getelementbyid("label").changecolor();'>change color!</a> To make it possible to push events in the other direction, you need to make your objects available through the JavaScript document contexts. Using the addtojavascriptwindowobject method available from each QWebFrame of your QWebPage. This method allows you to add an object to the JavaScript context with a name: webview->page()->mainframe()-> addtojavascriptwindowobject( "eventsource", new eventsource( this ) ); To connect a signal from the object you have just added, you need to inject a piece of JavaScript into the web page context. This is done using the evaluatejavascript method. The code below connects the signal signalname from the eventsource object to the JavaScript function destfunction. You can even pass arguments from the signal to the connected JavaScript function. webview->page()->mainframe()-> evaluatejavascript( "eventsource.signalname.connect(destfunction);" ); If you want to add a Qt object to the JavaScript contents of pages viewed through a standard browser, there is a signal to be aware of. Each time the JavaScript context is cleared, the frame emits the javascriptwindowobjectcleared signal. To ensure that your Qt object is available at all times, you need to connect to this signal and make your addtojavascriptwindowobject calls there. The Qt WebKit integration lets you create applications where the native C++ interacts with the JavaScript context in a seamless manner. This is the foundation of powerful hybrid applications, and Qt makes it easy. 2008 Nokia Corporation and/or its subsidiaries. Qt Features for Hybrid Web/Native Application Development 3

Using the Client Side Storage to Share Data With HTML 5, the web standard moves closer to the desktop in the same way as the desktop has started to integrate the web. One of the bigger changes in this direction is the introduction of client side storage. This gives each origin (i.e. each web page context) a SQL capable database engine on the client machine. This can be used to cache data locally, to reduce traffic and make the page available off-line. It can also be used to store large quantities of data in a structured, searchable way. The client side storage is available from JavaScript. The idea is to search the database from your JavaScript code and generate the HTML from the search result. This is done using the opendatabase and transaction functions. Assuming the database is present and filled, the following snippet shows the idea. db = opendatabase("testdb ", "1.0", "Client side storage test", 200000); db.transaction(function(tx) { tx.executesql("select id, text FROM Texts", [], function(tx, result) { for (var i = 0; i < result.rows.length; ++i) { var row = result.rows.item(i); processtext( row['id'], row['text'] ); } }, function(tx, error) { alert('failed to retrieve texts from the database - ' + error.message); return; }); }); Using the Qt WebKit integration, you can access the same databases through Qt's SQL module. This can be a very useful feature in a hybrid application. For example, the web page half of you application can use exactly the same mechanism for keeping data as when sharing data with your native application half. To avoid security breaches, the client side databases are only accessible through JavaScript from the right security origin. From your native C++ code you can access all security origins through the static QWebSecurityOrigin::allOrigins method, or via the QWebFrame::securityOrigin method. Given an origin object, you can get access to a list of QWebDatabase objects through the databases method. Each web database object has a filename property that can be used to open the database for access from the native code. 2008 Nokia Corporation and/or its subsidiaries. Qt Features for Hybrid Web/Native Application Development 4

QWebDatabase webdb = mysecurityorigin.databases()[index]; QSqlDatabase sqldb = QSqlDatabase::addDatabase("QSQLITE", "webconnection"); sqldb.setdatabasename(webdb.filename()); if (sqldb.open()) { QStringList tables = sqldb.tables();... } Combining this data sharing mechanism with the ability to connect events between the web and your native application, makes it easy to blur the border between web and desktop. Transforming the Web Much of the data available through the web is not suitable for direct presentation. Examples are news feeds, geo data and other application specific data formats. Qt s networking module makes it possible to download such data in an easy manner. Parsing the data and converting it into a suitable format can then be handled by your custom code or, for instance, by the QtXmlPatterns module. The latter is handy when the output format is expected to be XML, or if you want to display it in a web page, XHTML. In this section we will walk through the interesting parts of a small example downloading a news feed, converting it from XML to XHTML using an XSL transform, before presenting it through a QWebView as shown in figure 1. Figure 1: A news feed from ArsTechnica shown as XHTML using a QWebView. 2008 Nokia Corporation and/or its subsidiaries. Qt Features for Hybrid Web/Native Application Development 5

The QNetworkAccessManager class allows you to easily handle the interaction between a client and a web server. It helps you handle details such as proxy and cache settings, but also cookies and SSL/TSL sessions. All in all, it makes it easy for the average case to upload or download data -- but allows you to handle complex sessions with logins, certificates, etc.. To download the news feed for our example, all we need to do is create a QNetworkAccessManager and call its get method. The result is returned through the finished(qnetworkreply*) signal. However, as you can tell from the source code below, the reply object is available from the moment you make the request. This allows us to monitor the progress of the request by listening to the downloadprogress(qint64,qint64) signal. {... QNetworkAccessManager *manager = new QNetworkAccessManager( this ); connect( manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleReply(QNetworkReply*)) ); connect( manager, SIGNAL(finished(QNetworkReply*)), m_progressbar, SLOT(hide()) ); QNetworkReply *reply = manager->get( QNetworkRequest( QUrl( feedurl ) ) ); } connect( reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateProgress(qint64,qint64)) ); When the request is finished, the QNetworkReply object holds the entire reply. This reply needs further processing before it can be presented to users. In the case of an XML news feed such as RSS or ATOM, the processing can be done using an XSL transformation. In the case of this transformation, we use convert each item-node into a XHTML table row, populating the columns with the contents of the tags pubdate and title. This XSL template is part of a larger file containing more rules and the rest of the XHTML tags surrounding the table data. <xsl:template match="item"> <tr> </tr> <td><xsl:value-of select="pubdate"/></td> <td><xsl:value-of select="title"/></td> </xsl:template> 2008 Nokia Corporation and/or its subsidiaries. Qt Features for Hybrid Web/Native Application Development 6

The XSL query is combined with the reply given from the QNetworkReply object using a QXmlQuery object. This objects lets us perform XQueries on our XML data, transforming it from the news feed into XHTML. In the code below, the replybuffer contains the reply from the QNetworkReply. The queryfile is a QFile object with the XSL query and the resultbuffer is a QIODevice wrapping the QByteArray result into an interface suitable for QXmlQuery. The result is then displayed through the QWebView m_webview using the sethtml method. {... QXmlQuery qry( QXmlQuery::XSLT20 ); qry.setfocus( &replybuffer ); qry.setquery( &queryfile ); qry.evaluateto( &resultbuffer ); } m_webview->sethtml( QString(result) ); As you can see, Qt gives you all the tools that you need to easily download, process and display data from the Web. The combination of QNetworkAccessManager, QXmlQuery and QWebView forms a flexible flow from unformatted XML to data displayed on the screen. If your data is not XML, you can still use the QXmlQuery by providing a QAbstractXmlNodeModel, modeling non- XML data into XML nodes. 2008 Nokia Corporation and/or its subsidiaries. Qt Features for Hybrid Web/Native Application Development 7

Summary By providing the means for seamless integration between native C++ objects and JavaScript, Qt is the ideal platform for hybrid application development. The interaction between these two worlds is not limited to sharing data. Just like data, events can be passed both ways too. Hybrid applications have a number of attractive features. For instance, the user knows the web metaphor and is used to working with it. As parts of the application is deployed over the web, it can be updated without having to install anything on each user s machine. Another benefit is the separation of style from content using style sheets. Creating hybrid applications using Qt takes this one step further parts of your application are scripted, other parts consist of native code. The user interface can comprise of code, generated widgets, HTML or CSS. The combination of the Qt WebKit integration, QtNetwork and QtXmlPatterns lets you harness the power of native code and the flexibility of HTML, CSS and JavaScript. These are the tools for building the next generation of applications. For more information on the Qt WebKit Integration, visit http://www.qtsoftware.com/products or browse the Qt technical documentation at http://doc.trolltech.com/qtwebkit.html. 2008 Nokia Corporation and/or its subsidiaries. Qt Features for Hybrid Web/Native Application Development 8

White Paper About Qt Software: Qt Software (formerly Trolltech) is a global leader in cross-platform application frameworks. Nokia acquired Trolltech in June 2008, renamed it to Qt Software as a group within Nokia. Qt allows open source and commercial customers to code less, create more and deploy everywhere. Qt enables developers to build innovative services and applications once and then extend the innovation across all major desktop, mobile and other embedded platforms without rewriting the code. Qt is also used by multiple leading consumer electronics vendors to create advanced user interfaces for Linux devices. Qt underpins Nokia strategy to develop a wide range of products and experiences that people can fall in love with. About Nokia Nokia is the world leader in mobility, driving the transformation and growth of the converging Internet and communications industries. We make a wide range of mobile devices with services and software that enable people to experience music, navigation, video, television, imaging, games, business mobility and more. Developing and growing our offering of consumer Internet services, as well as our enterprise solutions and software, is a key area of focus. We also provide equipment, solutions and services for communications networks through Nokia Siemens Networks. Oslo, Norway +47 21 60 48 00 Redwood City, CA, USA +1 650-551-1676 Beijing, China +86 10 6588 8836 qt-info@nokia.com www.qtsoftware.com 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.