summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2014-12-22 13:05:18 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2014-12-22 14:20:04 +0100
commit6634ff02232e306547bcff4c2a405a2d36f2b139 (patch)
tree32ad158e08a4bbed2412ad782cc2a4231119afdd /examples
parent8eafcc2d6960390d6784a1c5bb075d6314041fdf (diff)
Make chat example more error tolerant
It becomes more obvious on platforms which do not support Bluetooth that the example will not work. Change-Id: Ia6d249a4a891f93abf29910500ba164662308889 Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/bluetooth/chat/Search.qml3
-rw-r--r--examples/bluetooth/chat/chat.qml8
-rw-r--r--examples/bluetooth/chat/qmlchat.cpp6
3 files changed, 16 insertions, 1 deletions
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 <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#include <QDebug>
+#include <QBluetoothLocalDevice>
int main(int argc, char *argv[])
{
QGuiApplication application(argc, argv);
+ QList<QBluetoothHostInfo> 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));