/**************************************************************************** ** ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the documentation of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:FDL$ ** GNU Free Documentation License ** Alternatively, this file may be used under the terms of the GNU Free ** Documentation License version 1.3 as published by the Free Software ** Foundation and appearing in the file included in the packaging of ** this file. ** ** Other Usage ** Alternatively, this file may be used in accordance with the terms ** and conditions contained in a signed written agreement between you ** and Nokia. ** ** ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ /*! \example webkit/imageanalyzer \startpage {index.html}{Qt Reference Documentation} \title The Webkit Bridge Tutorial - Hybrid Client Application \brief In this example, we will show how to write a hybrid application using \l{The QtWebKit Bridge}{QtWebKit Bridge}, which distinguishes itself from a thin client in that it performs heavy calculations on the client side in C++, like a native application, but presents nothing more than a \c QWebView for its user interface, displaying web content written in HTML/JavaScript. The application uses QtConcurrent to distribute its work across as many CPU cores as are available from the system, so it can process each image in parallel. For the full reference documentation of QtWebKit hybrid development, see \l{qtwebkit-bridge.html}{The QtWebKit Bridge}. Initially, you will see a user interface with an empty list of images. Clicking on some of the images in the lower pane below adds them to the list view above, as shown in the screenshot below. \image webkit-imageanalyzer-screenshot.png Now, we can click on \bold Analyze, and each image is analyzed using some computationally intensive C++ function, in parallel and on different cores. Progress is shown while the analysis is proceeding. \image webkit-imageanalyzer-progress.png and in the end, we will see something like this, where the average RGB values of each image are shown. \image webkit-imageanalyzer-complete.png The MainWindow is defined in C++, and creates a \l QNetworkDiskCache and a \l QWebView, and tells the \l QWebView to load the starting page, providing us with a user interface for the client. \snippet examples/webkit/imageanalyzer/mainwindow.cpp MainWindow - constructor In this example, the sample content is addressed with the \tt qrc:/index.html URL. \tt qrc:/ indicates that the file is stored as a Qt resource (attached to the executable). In a real-world application, the content and images would likely be retrieved from the network rather than from resources. We wish to initialize an object reference in the JavaScript web page to point to our \tt ImageAnalyzer before any other scripts are run. To do this, we connect the \l{QWebFrame::}{javaScriptWindowObjectCleared()} signal to a slot which does the object creation and handoff to JavaScript. \snippet examples/webkit/imageanalyzer/mainwindow.cpp MainWindow - addJSObject The ImageAnalyzer object is created and added to a JavaScript object on the web page's mainFrame with \c addToJavaScriptWindowObject(). The start page is resources/index.html. In one of its