summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-06-19 13:09:47 +0200
committerAlex Blasche <alexander.blasche@qt.io>2017-06-20 06:06:00 +0000
commit71f22ac56c744ed71ccc26423a9c7a08fc4eb4e6 (patch)
tree09e803eecf6bbc742b0d98e5fb74615faae50323 /examples/bluetooth
parent4986d02c7b844f5fe920abf3932b8f9500e345eb (diff)
Properly handle disconnect socket event in QML chat example
Prior to this change the state transtion of the BluetoothSocket instance was not distinguishing between the varios state types. It always assumes any state transtion was a transition to "Connected". Change-Id: I584b6c467dc77ac0602562d6792c16bf357d831c Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'examples/bluetooth')
-rw-r--r--examples/bluetooth/chat/Search.qml3
-rw-r--r--examples/bluetooth/chat/chat.qml20
2 files changed, 21 insertions, 2 deletions
diff --git a/examples/bluetooth/chat/Search.qml b/examples/bluetooth/chat/Search.qml
index f1f8f6ac..ea542462 100644
--- a/examples/bluetooth/chat/Search.qml
+++ b/examples/bluetooth/chat/Search.qml
@@ -46,6 +46,9 @@ Rectangle {
function appendText(newText) {
searchText.text += newText
}
+ function setText(newText) {
+ searchText.text = newText
+ }
width: searchText.width + 40;
height: searchText.height + bluetoothImage.height + 40;
diff --git a/examples/bluetooth/chat/chat.qml b/examples/bluetooth/chat/chat.qml
index 7613519a..06f2fc49 100644
--- a/examples/bluetooth/chat/chat.qml
+++ b/examples/bluetooth/chat/chat.qml
@@ -91,8 +91,24 @@ Item {
connected: true
onSocketStateChanged: {
- console.log("Connected to server")
- top.state = "chatActive"
+ switch (socketState) {
+ case BluetoothSocket.Unconnected:
+ case BluetoothSocket.NoServiceSet:
+ searchBox.animationRunning = false;
+ searchBox.setText("\nNo connection. \n\nPlease restart app.");
+ top.state = "begin";
+ break;
+ case BluetoothSocket.Connected:
+ console.log("Connected to server ");
+ top.state = "chatActive"; // move to chat UI
+ break;
+ case BluetoothSocket.Connecting:
+ case BluetoothSocket.ServiceLookup:
+ case BluetoothSocket.Closing:
+ case BluetoothSocket.Listening:
+ case BluetoothSocket.Bound:
+ break;
+ }
}
//! [BluetoothSocket-1]
//! [BluetoothSocket-3]