From e82b9c37609ab8f686a6dfd312bf0423bb740f35 Mon Sep 17 00:00:00 2001 From: Venugopal Shivashankar Date: Tue, 22 Dec 2015 13:28:10 +0100 Subject: Example: Modify JavaScript part of the HTML The baseUrl that is used to connect to a WebSocket server is derived from the query parameters set to the URL. These parameters are ignored by the QDesktopServices::openUrl implementations specific to Windows and OS X. Ubuntu uses the default implementation that retains the query parameters. This means the browser instance will fail to open the local file URL on Ubuntu because it includes the query parameters, so query parameters should never be set. Moreover, the example creates a QWebSocketServer instance, which is available at ws://localhost:12345, so the it is safe to hardcode the address in the JavaScript. The cleaner approach would be to use a URLHandler as described in http://doc.qt.io/qt-5/qdesktopservices.html#url-handlers, but that complicates the example. Change-Id: I5b5df2b7b816ce0bbfb16a85c036ed379616f04a Task-number: QTBUG-46541 Reviewed-by: Milian Wolff --- examples/webchannel/standalone/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'examples/webchannel/standalone/main.cpp') diff --git a/examples/webchannel/standalone/main.cpp b/examples/webchannel/standalone/main.cpp index 8005301..9c03370 100644 --- a/examples/webchannel/standalone/main.cpp +++ b/examples/webchannel/standalone/main.cpp @@ -132,7 +132,6 @@ int main(int argc, char** argv) // open a browser window with the client HTML page QUrl url = QUrl::fromLocalFile(BUILD_DIR "/index.html"); - url.setQuery(QStringLiteral("webChannelBaseUrl=") + server.serverUrl().toString()); QDesktopServices::openUrl(url); dialog.displayMessage(QObject::tr("Initialization complete, opening browser at %1.").arg(url.toDisplayString())); -- cgit v1.2.1 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/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'examples/webchannel/standalone/main.cpp') 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