From 6634ff02232e306547bcff4c2a405a2d36f2b139 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 22 Dec 2014 13:05:18 +0100 Subject: Make chat example more error tolerant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It becomes more obvious on platforms which do not support Bluetooth that the example will not work. Change-Id: Ia6d249a4a891f93abf29910500ba164662308889 Reviewed-by: Topi Reiniƶ --- examples/bluetooth/chat/Search.qml | 3 ++- examples/bluetooth/chat/chat.qml | 8 ++++++++ examples/bluetooth/chat/qmlchat.cpp | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/bluetooth/chat/Search.qml b/examples/bluetooth/chat/Search.qml index 4557971b..47fbb6ab 100644 --- a/examples/bluetooth/chat/Search.qml +++ b/examples/bluetooth/chat/Search.qml @@ -41,7 +41,7 @@ import QtQuick 2.2 Rectangle { - property bool animationRunning: ranimation.running + property bool animationRunning: true function appendText(newText) { searchText.text += newText @@ -75,6 +75,7 @@ Rectangle { duration: 2000 loops: Animation.Infinite alwaysRunToEnd: true + running: animationRunning } } diff --git a/examples/bluetooth/chat/chat.qml b/examples/bluetooth/chat/chat.qml index 6614d53c..6a2830ad 100644 --- a/examples/bluetooth/chat/chat.qml +++ b/examples/bluetooth/chat/chat.qml @@ -57,10 +57,18 @@ Item { //! [BtDiscoveryModel-1] onRunningChanged : { if (!btModel.running && top.state == "begin" && !serviceFound) { + searchBox.animationRunning = false; searchBox.appendText("\nNo service found. \n\nPlease start server\nand restart app.") } } + onErrorChanged: { + if (error != BluetoothDiscoveryModel.NoError && !btModel.running) { + searchBox.animationRunning = false + searchBox.appendText("\n\nDiscovery failed.\nPlease ensure Bluetooth is available.") + } + } + //! [BtDiscoveryModel-2] onServiceDiscovered: { if (serviceFound) diff --git a/examples/bluetooth/chat/qmlchat.cpp b/examples/bluetooth/chat/qmlchat.cpp index aefc900a..6e23fe13 100644 --- a/examples/bluetooth/chat/qmlchat.cpp +++ b/examples/bluetooth/chat/qmlchat.cpp @@ -43,11 +43,17 @@ #include #include #include +#include int main(int argc, char *argv[]) { QGuiApplication application(argc, argv); + QList infos = QBluetoothLocalDevice::allDevices(); + if (infos.isEmpty()) + qWarning() << "Missing Bluetooth local device. " + "Example will not work properly."; + const QString mainQmlApp = QLatin1String("qrc:/chat.qml"); QQuickView view; view.setSource(QUrl(mainQmlApp)); -- cgit v1.2.3