/usr/share/qt5/doc/qtbluetooth/qtbluetooth-chat-example.html is in qtconnectivity5-doc-html 5.9.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- chat.qdoc -->
<title>Bluetooth QML Chat Example | Qt Bluetooth 5.9</title>
<link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
<script type="text/javascript">
document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
// loading style sheet breaks anchors that were jumped to before
// so force jumping to anchor again
setTimeout(function() {
var anchor = location.hash;
// need to jump to different anchor first (e.g. none)
location.hash = "#";
setTimeout(function() {
location.hash = anchor;
}, 0);
}, 0);
</script>
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<table><tr>
<td >Qt 5.9</td><td ><a href="qtbluetooth-index.html">Qt Bluetooth</a></td><td >Bluetooth QML Chat Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.5 Reference Documentation</td>
</tr></table>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#interacting-with-the-server">Interacting with the Server</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Bluetooth QML Chat Example</h1>
<span class="subtitle"></span>
<!-- $$$chat-description -->
<div class="descr"> <a name="details"></a>
<p><i>Bluetooth QML Chat</i> example shows how to use the <a href="qtbluetooth-index.html">Qt Bluetooth</a> QML API to communicate with another application on a remote device using Bluetooth.</p>
<p class="centerAlign"><img src="images/chat-view.png" alt="" /></p><p>The Bluetooth QML Chat example implements a simple chat program between two parties. The application acts as client and attempts to connect to a Bluetooth socket server. It uses the <a href="qml-qtbluetooth-bluetoothdiscoverymodel.html">BluetoothDiscoveryModel</a> type to find the server and <a href="qml-qtbluetooth-bluetoothsocket.html">BluetoothSocket</a> type to facilitate the data exchange.</p>
<a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<p>The example only works in connection with the <a href="qtbluetooth-btchat-example.html">Bluetooth Chat Example</a>. The Bluetooth Chat example launches the chat service and advertises it via the Bluetooth SDP protocol. It is important that the device running the Bluetooth Chat example actively advertises its SDP services. This can be checked using the <a href="qbluetoothlocaldevice.html#hostMode">QBluetoothLocalDevice::hostMode</a> property.</p>
<a name="interacting-with-the-server"></a>
<h2 id="interacting-with-the-server">Interacting with the Server</h2>
<p>The example application immediately starts the service discovery using the <a href="qml-qtbluetooth-bluetoothdiscoverymodel.html">BluetoothDiscoveryModel</a> type:</p>
<pre class="qml">
<span class="type"><a href="qml-qtbluetooth-bluetoothdiscoverymodel.html">BluetoothDiscoveryModel</a></span> {
<span class="name">id</span>: <span class="name">btModel</span>
<span class="name">running</span>: <span class="number">true</span>
<span class="name">discoveryMode</span>: <span class="name">BluetoothDiscoveryModel</span>.<span class="name">FullServiceDiscovery</span>
<span class="name">uuidFilter</span>: <span class="name">targetUuid</span> <span class="comment">//e8e10f95-1a70-4b27-9ccf-02010264e9c8</span>
}
</pre>
<p>The <a href="qml-qtbluetooth-bluetoothdiscoverymodel.html#uuidFilter-prop">uuidFilter</a> property is used to only search for the chat server UUID and the <a href="qml-qtbluetooth-bluetoothdiscoverymodel.html#running-prop">running</a> property activates the search. Once a service with a matching UUID is found the model emits the <a href="qml-qtbluetooth-bluetoothdiscoverymodel.html#serviceDiscovered-signal">serviceDiscovered(BluetoothService)</a> signal.</p>
<pre class="qml">
<span class="name">onServiceDiscovered</span>: {
<span class="keyword">if</span> (<span class="name">serviceFound</span>)
<span class="keyword">return</span>
<span class="name">serviceFound</span> <span class="operator">=</span> <span class="number">true</span>
<span class="name">console</span>.<span class="name">log</span>(<span class="string">"Found new service "</span> <span class="operator">+</span> <span class="name">service</span>.<span class="name">deviceAddress</span> <span class="operator">+</span> <span class="string">" "</span> <span class="operator">+</span> <span class="name">service</span>.<span class="name">deviceName</span> <span class="operator">+</span> <span class="string">" "</span> <span class="operator">+</span> <span class="name">service</span>.<span class="name">serviceName</span>);
<span class="name">searchBox</span>.<span class="name">appendText</span>(<span class="string">"\nConnecting to server..."</span>)
<span class="name">remoteDeviceName</span> <span class="operator">=</span> <span class="name">service</span>.<span class="name">deviceName</span>
<span class="name">socket</span>.<span class="name">setService</span>(<span class="name">service</span>)
}
</pre>
<p>The <a href="qml-qtbluetooth-bluetoothservice.html">BluetoothService</a> type encapsulates the details of the found chat server, such as the <a href="qml-qtbluetooth-bluetoothservice.html#serviceName-prop">name</a> and <a href="qml-qtbluetooth-bluetoothservice.html#serviceDescription-prop">description</a> of the service, as well as the <a href="qml-qtbluetooth-bluetoothservice.html#deviceName-prop">name</a> and <a href="qml-qtbluetooth-bluetoothservice.html#deviceAddress-prop">address</a> of the Bluetooth device offering the chat server. It is passed to the <a href="qml-qtbluetooth-bluetoothsocket.html">BluetoothSocket</a> to establish the connection.</p>
<p>Once the connection is established the socket's state is managed as follows:</p>
<pre class="qml">
<span class="type"><a href="qml-qtbluetooth-bluetoothsocket.html">BluetoothSocket</a></span> {
<span class="name">id</span>: <span class="name">socket</span>
<span class="name">connected</span>: <span class="number">true</span>
<span class="name">onSocketStateChanged</span>: {
<span class="keyword">switch</span> (<span class="name">socketState</span>) {
<span class="keyword">case</span> <span class="name">BluetoothSocket</span>.<span class="name">Unconnected</span>:
<span class="keyword">case</span> <span class="name">BluetoothSocket</span>.<span class="name">NoServiceSet</span>:
<span class="name">searchBox</span>.<span class="name">animationRunning</span> <span class="operator">=</span> <span class="number">false</span>;
<span class="name">searchBox</span>.<span class="name">setText</span>(<span class="string">"\nNo connection. \n\nPlease restart app."</span>);
<span class="name">top</span>.<span class="name">state</span> <span class="operator">=</span> <span class="string">"begin"</span>;
<span class="keyword">break</span>;
<span class="keyword">case</span> <span class="name">BluetoothSocket</span>.<span class="name">Connected</span>:
<span class="name">console</span>.<span class="name">log</span>(<span class="string">"Connected to server "</span>);
<span class="name">top</span>.<span class="name">state</span> <span class="operator">=</span> <span class="string">"chatActive"</span>; <span class="comment">// move to chat UI</span>
<span class="keyword">break</span>;
<span class="keyword">case</span> <span class="name">BluetoothSocket</span>.<span class="name">Connecting</span>:
<span class="keyword">case</span> <span class="name">BluetoothSocket</span>.<span class="name">ServiceLookup</span>:
<span class="keyword">case</span> <span class="name">BluetoothSocket</span>.<span class="name">Closing</span>:
<span class="keyword">case</span> <span class="name">BluetoothSocket</span>.<span class="name">Listening</span>:
<span class="keyword">case</span> <span class="name">BluetoothSocket</span>.<span class="name">Bound</span>:
<span class="keyword">break</span>;
}
}
<span class="comment">//...</span>
}
</pre>
<p>The payload is received via the <a href="qml-qtbluetooth-bluetoothsocket.html#stringData-prop">stringData</a> property:</p>
<pre class="qml">
<span class="name">onStringDataChanged</span>: {
<span class="name">console</span>.<span class="name">log</span>(<span class="string">"Received data: "</span> )
var <span class="name">data</span> = <span class="name">remoteDeviceName</span> <span class="operator">+</span> <span class="string">": "</span> <span class="operator">+</span> <span class="name">socket</span>.<span class="name">stringData</span>;
<span class="name">data</span> <span class="operator">=</span> <span class="name">data</span>.<span class="name">substring</span>(<span class="number">0</span>, <span class="name">data</span>.<span class="name">indexOf</span>(<span class="string">'\n'</span>))
<span class="name">chatContent</span>.<span class="name">append</span>({content: <span class="name">data</span>})
}
</pre>
<p>And sent by setting the same property:</p>
<pre class="qml">
<span class="name">socket</span>.<span class="name">stringData</span> <span class="operator">=</span> <span class="name">data</span>
</pre>
<p>Files:</p>
<ul>
<li><a href="qtbluetooth-chat-button-qml.html">chat/Button.qml</a></li>
<li><a href="qtbluetooth-chat-inputbox-qml.html">chat/InputBox.qml</a></li>
<li><a href="qtbluetooth-chat-search-qml.html">chat/Search.qml</a></li>
<li><a href="qtbluetooth-chat-chat-qml.html">chat/chat.qml</a></li>
<li><a href="qtbluetooth-chat-qmlchat-cpp.html">chat/qmlchat.cpp</a></li>
<li><a href="qtbluetooth-chat-chat-pro.html">chat/chat.pro</a></li>
<li><a href="qtbluetooth-chat-chat-qrc.html">chat/chat.qrc</a></li>
</ul>
<p>Images:</p>
<ul>
<li><a href="images/used-in-examples/chat/images/clear.png">chat/images/clear.png</a></li>
<li><a href="images/used-in-examples/chat/images/default.png">chat/images/default.png</a></li>
<li><a href="images/used-in-examples/chat/images/lineedit-bg.png">chat/images/lineedit-bg.png</a></li>
</ul>
</div>
<!-- @@@chat -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2017 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|