From 47028349eabff3fadedcfe1918faa372537c018f Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 30 Aug 2017 16:52:10 +0200 Subject: 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 --- .../webchannel/chatclient-qml/qmlchatclient.qml | 27 +++++++++++++++++----- 1 file 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(); + } } } -- cgit v1.2.1