From eaebf63c17964d449b75b7d2d6af3d0efaee5ed9 Mon Sep 17 00:00:00 2001 From: Venugopal Shivashankar Date: Fri, 8 Jan 2016 14:54:47 +0100 Subject: Example: Add code to copy the JS file from the resource system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The JS file lives in the src/webchannel directory, and there is a QMake magic in place to copy it to the build directory. But this mechanism fails when the example is run from the Qt binary pkg, which does not include the sources. The JS file must be copied to the build directory either manually or programmatically to run the example. Change-Id: Ib56d9348a8bf1a599e2db5235e0545cd7a8f3bb1 Task-number: QTBUG-46541 Reviewed-by: Topi Reiniƶ Reviewed-by: Milian Wolff --- examples/webchannel/standalone/index.html | 3 ++- examples/webchannel/standalone/main.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/webchannel/standalone/index.html b/examples/webchannel/standalone/index.html index cc3d72d..b5a9a49 100644 --- a/examples/webchannel/standalone/index.html +++ b/examples/webchannel/standalone/index.html @@ -14,7 +14,8 @@ if (location.search != "") var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]); else - var baseUrl = "ws://localhost:12345"); + var baseUrl = "ws://localhost:12345"; + output("Connecting to WebSocket server at " + baseUrl + "."); var socket = new WebSocket(baseUrl); diff --git a/examples/webchannel/standalone/main.cpp b/examples/webchannel/standalone/main.cpp index 9c03370..bd2b0a9 100644 --- a/examples/webchannel/standalone/main.cpp +++ b/examples/webchannel/standalone/main.cpp @@ -38,8 +38,8 @@ #include #include #include -#include - +#include +#include #include #include "../shared/websocketclientwrapper.h" @@ -111,6 +111,11 @@ int main(int argc, char** argv) { QApplication app(argc, argv); + QFileInfo jsFileInfo(QDir::currentPath() + "/qwebchannel.js"); + + if (!jsFileInfo.exists()) + QFile::copy(":/qtwebchannel/qwebchannel.js",jsFileInfo.absoluteFilePath()); + // setup the QWebSocketServer QWebSocketServer server(QStringLiteral("QWebChannel Standalone Example Server"), QWebSocketServer::NonSecureMode); if (!server.listen(QHostAddress::LocalHost, 12345)) { -- cgit v1.2.1