diff options
Diffstat (limited to 'examples/bluetooth/chat')
-rw-r--r-- | examples/bluetooth/chat/Search.qml | 3 | ||||
-rw-r--r-- | examples/bluetooth/chat/chat.pro | 1 | ||||
-rw-r--r-- | examples/bluetooth/chat/chat.qml | 25 | ||||
-rw-r--r-- | examples/bluetooth/chat/doc/src/chat.qdoc | 12 | ||||
-rw-r--r-- | examples/bluetooth/chat/qmlchat.cpp | 18 |
5 files changed, 49 insertions, 10 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.pro b/examples/bluetooth/chat/chat.pro index 7bc5c8bd..36d815f9 100644 --- a/examples/bluetooth/chat/chat.pro +++ b/examples/bluetooth/chat/chat.pro @@ -1,4 +1,5 @@ QT = core bluetooth quick +android: QT += androidextras #see QTBUG-61392 SOURCES += qmlchat.cpp TARGET = qml_chat diff --git a/examples/bluetooth/chat/chat.qml b/examples/bluetooth/chat/chat.qml index ecac39fc..eee29789 100644 --- a/examples/bluetooth/chat/chat.qml +++ b/examples/bluetooth/chat/chat.qml @@ -53,7 +53,7 @@ Item { BluetoothDiscoveryModel { id: btModel running: true - discoveryMode: BluetoothDiscoveryModel.MinimalServiceDiscovery + discoveryMode: BluetoothDiscoveryModel.FullServiceDiscovery //! [BtDiscoveryModel-1] onRunningChanged : { if (!btModel.running && top.state == "begin" && !serviceFound) { @@ -81,7 +81,7 @@ Item { } //! [BtDiscoveryModel-2] //! [BtDiscoveryModel-3] - uuidFilter: "e8e10f95-1a70-4b27-9ccf-02010264e9c8" + uuidFilter: targetUuid //e8e10f95-1a70-4b27-9ccf-02010264e9c8 } //! [BtDiscoveryModel-3] @@ -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] @@ -107,6 +123,7 @@ Item { } //! [BluetoothSocket-4] //! [BluetoothSocket-2] + //... } //! [BluetoothSocket-2] diff --git a/examples/bluetooth/chat/doc/src/chat.qdoc b/examples/bluetooth/chat/doc/src/chat.qdoc index 4b5e8778..6fdf9b70 100644 --- a/examples/bluetooth/chat/doc/src/chat.qdoc +++ b/examples/bluetooth/chat/doc/src/chat.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt local connectivty modules. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -69,7 +69,7 @@ of the Bluetooth device offering the chat server. It is passed to the \l BluetoothSocket to establish the connection. - Once the connection is established the chat information is: + Once the connection is established the socket's state is managed as follows: \snippet chat/chat.qml BluetoothSocket-1 \snippet chat/chat.qml BluetoothSocket-2 diff --git a/examples/bluetooth/chat/qmlchat.cpp b/examples/bluetooth/chat/qmlchat.cpp index 8cd90bda..c6ff6341 100644 --- a/examples/bluetooth/chat/qmlchat.cpp +++ b/examples/bluetooth/chat/qmlchat.cpp @@ -44,9 +44,14 @@ #include <QtQml/QQmlContext> #include <QDebug> #include <QBluetoothLocalDevice> +#include <QtCore/QLoggingCategory> +#ifdef Q_OS_ANDROID +#include <QtAndroidExtras/QtAndroid> +#endif int main(int argc, char *argv[]) { + //QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); QGuiApplication application(argc, argv); QList<QBluetoothHostInfo> infos = QBluetoothLocalDevice::allDevices(); @@ -56,6 +61,19 @@ int main(int argc, char *argv[]) const QString mainQmlApp = QLatin1String("qrc:/chat.qml"); QQuickView view; + +#ifdef Q_OS_ANDROID + //workaround for Android's SDP discovery bug (see QTBUG-61392) + QString uuid; + if (QtAndroid::androidSdkVersion() >= 23) + uuid = QStringLiteral("c8e96402-0102-cf9c-274b-701a950fe1e8"); + else + uuid = QStringLiteral("e8e10f95-1a70-4b27-9ccf-02010264e9c8"); +#else + const QString uuid(QStringLiteral("e8e10f95-1a70-4b27-9ccf-02010264e9c8")); +#endif + + view.engine()->rootContext()->setContextProperty(QStringLiteral("targetUuid"), uuid); view.setSource(QUrl(mainQmlApp)); view.setResizeMode(QQuickView::SizeRootObjectToView); // Qt.quit() called in embedded .qml by default only emits |