summaryrefslogtreecommitdiff
path: root/examples/webchannel/chatclient-qml/qmlchatclient.qml
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@qt.io>2017-08-30 16:52:10 +0200
committerKai Koehne <kai.koehne@qt.io>2017-09-12 09:22:30 +0000
commit47028349eabff3fadedcfe1918faa372537c018f (patch)
tree8ba773da09853c860d68786b6f7c0ca864a71c70 /examples/webchannel/chatclient-qml/qmlchatclient.qml
parentf3456482e44a1ef4663870b427492f4513a231e7 (diff)
downloadqtwebchannel-47028349eabff3fadedcfe1918faa372537c018f.tar.gz
chatclient-qml: Show errors in a dialog
If the socket is closed the error was so far written to a non-existing element. Show a modal dialog then, instead. Also, do not make the login window visible until we have established a connection. Change-Id: I5045f8583a396f22b751e65b8bb73c609b51c9be Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'examples/webchannel/chatclient-qml/qmlchatclient.qml')
-rw-r--r--examples/webchannel/chatclient-qml/qmlchatclient.qml27
1 files changed, 21 insertions, 6 deletions
diff --git a/examples/webchannel/chatclient-qml/qmlchatclient.qml b/examples/webchannel/chatclient-qml/qmlchatclient.qml
index c2c3d8d..1bc67ec 100644
--- a/examples/webchannel/chatclient-qml/qmlchatclient.qml
+++ b/examples/webchannel/chatclient-qml/qmlchatclient.qml
@@ -50,6 +50,7 @@
****************************************************************************/
import QtQuick 2.2
+import QtQuick.Dialogs 1.2
import QtQuick.Controls 2.0
import QtQuick.Window 2.0
import QtQuick.Layouts 1.1
@@ -80,16 +81,18 @@ ApplicationWindow {
property var onmessage
- active: false
+ active: true
url: "ws://localhost:12345"
onStatusChanged: {
switch (socket.status) {
case WebSocket.Error:
- console.error("Error: " + socket.errorString);
+ errorDialog.text = "Error: " + socket.errorString;
+ errorDialog.visible = true;
break;
case WebSocket.Closed:
- messageBox.text += "\nSocket closed";
+ errorDialog.text = "Error: Socket at " + url + " closed.";
+ errorDialog.visible = true;
break;
case WebSocket.Open:
//open the webchannel with the socket as transport
@@ -116,6 +119,8 @@ ApplicationWindow {
ch.objects.chatserver.keepAliveResponse(loginName.text);
});
});
+
+ loginWindow.show();
break;
}
}
@@ -203,8 +208,18 @@ ApplicationWindow {
}
}
- Component.onCompleted: {
- loginWindow.show();
- socket.active = true; //connect
+ MessageDialog {
+ id: errorDialog
+
+ icon: StandardIcon.Critical
+ standardButtons: StandardButton.Close
+ title: "Chat client"
+
+ onAccepted: {
+ Qt.quit();
+ }
+ onRejected: {
+ Qt.quit();
+ }
}
}