diff options
authorVenugopal Shivashankar <>2015-12-22 13:28:10 +0100
committerVenugopal Shivashankar <>2016-01-04 14:33:42 +0000
commite82b9c37609ab8f686a6dfd312bf0423bb740f35 (patch)
parent97577a0f27a1f427948871ae535645a2e0788bf7 (diff)
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, but that complicates the example. Change-Id: I5b5df2b7b816ce0bbfb16a85c036ed379616f04a Task-number: QTBUG-46541 Reviewed-by: Milian Wolff <>
2 files changed, 4 insertions, 2 deletions
diff --git a/examples/webchannel/standalone/index.html b/examples/webchannel/standalone/index.html
index 778a502..cc3d72d 100644
--- a/examples/webchannel/standalone/index.html
+++ b/examples/webchannel/standalone/index.html
@@ -11,7 +11,10 @@
output.innerHTML = output.innerHTML + message + "\n";
window.onload = function() {
- var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec([1]);
+ if ( != "")
+ var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec([1]);
+ else
+ 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 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());
dialog.displayMessage(QObject::tr("Initialization complete, opening browser at %1.").arg(url.toDisplayString()));