Sophie

Sophie

distrib > Mageia > 7 > aarch64 > by-pkgid > 814a2b4c48f3ef6444b2ff5bf854d05a > files > 81

qtconnectivity5-doc-5.12.6-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qbluetoothsocket.cpp -->
  <title>QBluetoothSocket Class | Qt Bluetooth 5.12.6</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.12</td><td ><a href="qtbluetooth-index.html">Qt Bluetooth</a></td><td ><a href="qtbluetooth-module.html">C++ Classes</a></td><td >QBluetoothSocket</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtbluetooth-index.html">Qt 5.12.6 Reference Documentation</a></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="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li>
<li class="level1"><a href="#signals">Signals</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#reimplemented-protected-functions">Reimplemented Protected Functions</a></li>
<li class="level1"><a href="#protected-variables">Protected Variables</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QBluetoothSocket Class</h1>
<!-- $$$QBluetoothSocket-brief -->
<p>The <a href="qbluetoothsocket.html">QBluetoothSocket</a> class enables connection to a Bluetooth device running a bluetooth server. <a href="#details">More...</a></p>
<!-- @@@QBluetoothSocket -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QBluetoothSocket&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += bluetooth</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 5.2</td></tr></table></div><ul>
<li><a href="qbluetoothsocket-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#SocketError-enum">SocketError</a></b> { UnknownSocketError, NoSocketError, HostNotFoundError, ServiceNotFoundError, ..., RemoteHostClosedError }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#SocketState-enum">SocketState</a></b> { UnconnectedState, ServiceLookupState, ConnectingState, ConnectedState, ..., ListeningState }</td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#QBluetoothSocket">QBluetoothSocket</a></b>(QBluetoothServiceInfo::Protocol <i>socketType</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#QBluetoothSocket-1">QBluetoothSocket</a></b>(QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#dtor.QBluetoothSocket">~QBluetoothSocket</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#abort">abort</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#connectToService">connectToService</a></b>(const QBluetoothServiceInfo &amp;<i>service</i>, QIODevice::OpenMode <i>openMode</i> = ReadWrite)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#connectToService-1">connectToService</a></b>(const QBluetoothAddress &amp;<i>address</i>, const QBluetoothUuid &amp;<i>uuid</i>, QIODevice::OpenMode <i>openMode</i> = ReadWrite)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#connectToService-2">connectToService</a></b>(const QBluetoothAddress &amp;<i>address</i>, quint16 <i>port</i>, QIODevice::OpenMode <i>openMode</i> = ReadWrite)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#disconnectFromService">disconnectFromService</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QBluetoothSocket::SocketError </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#error">error</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#errorString">errorString</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QBluetoothAddress </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#localAddress">localAddress</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#localName">localName</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> quint16 </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#localPort">localPort</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QBluetoothAddress </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#peerAddress">peerAddress</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#peerName">peerName</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> quint16 </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#peerPort">peerPort</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QBluetooth::SecurityFlags </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#preferredSecurityFlags">preferredSecurityFlags</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#setPreferredSecurityFlags">setPreferredSecurityFlags</a></b>(QBluetooth::SecurityFlags <i>flags</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#setSocketDescriptor">setSocketDescriptor</a></b>(int <i>socketDescriptor</i>, QBluetoothServiceInfo::Protocol <i>socketType</i>, QBluetoothSocket::SocketState <i>socketState</i> = ConnectedState, QIODevice::OpenMode <i>openMode</i> = ReadWrite)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#socketDescriptor">socketDescriptor</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QBluetoothServiceInfo::Protocol </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#socketType">socketType</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QBluetoothSocket::SocketState </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#state">state</a></b>() const</td></tr>
</table></div>
<a name="reimplemented-public-functions"></a>
<h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual qint64 </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#bytesAvailable">bytesAvailable</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual qint64 </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#bytesToWrite">bytesToWrite</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#canReadLine">canReadLine</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#close">close</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#isSequential">isSequential</a></b>() const</td></tr>
</table></div>
<a name="signals"></a>
<h2 id="signals">Signals</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#connected">connected</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#disconnected">disconnected</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#error-1">error</a></b>(QBluetoothSocket::SocketError <i>error</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#stateChanged">stateChanged</a></b>(QBluetoothSocket::SocketState <i>state</i>)</td></tr>
</table></div>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#staticMetaObject-var">staticMetaObject</a></b></td></tr>
</table></div>
<a name="protected-functions"></a>
<h2 id="protected-functions">Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#doDeviceDiscovery">doDeviceDiscovery</a></b>(const QBluetoothServiceInfo &amp;<i>service</i>, QIODevice::OpenMode <i>openMode</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#setSocketError">setSocketError</a></b>(QBluetoothSocket::SocketError <i>error_</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#setSocketState">setSocketState</a></b>(QBluetoothSocket::SocketState <i>state</i>)</td></tr>
</table></div>
<a name="reimplemented-protected-functions"></a>
<h2 id="reimplemented-protected-functions">Reimplemented Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual qint64 </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#readData">readData</a></b>(char *<i>data</i>, qint64 <i>maxSize</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual qint64 </td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#writeData">writeData</a></b>(const char *<i>data</i>, qint64 <i>maxSize</i>)</td></tr>
</table></div>
<a name="protected-variables"></a>
<h2 id="protected-variables">Protected Variables</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QBluetoothSocketBasePrivate *</td><td class="memItemRight bottomAlign"><b><a href="qbluetoothsocket.html#d_ptr-var">d_ptr</a></b></td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QBluetoothSocket-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qbluetoothsocket.html">QBluetoothSocket</a> class enables connection to a Bluetooth device running a bluetooth server.</p>
<p><a href="qbluetoothsocket.html">QBluetoothSocket</a> supports two socket types, <a href="qbluetoothserviceinfo.html#Protocol-enum">L2CAP</a> and <a href="qbluetoothserviceinfo.html#Protocol-enum">RFCOMM</a>.</p>
<p><a href="qbluetoothserviceinfo.html#Protocol-enum">L2CAP</a> is a low level datagram-oriented Bluetooth socket. Android does not support <a href="qbluetoothserviceinfo.html#Protocol-enum">L2CAP</a> for socket connections.</p>
<p><a href="qbluetoothserviceinfo.html#Protocol-enum">RFCOMM</a> is a reliable, stream-oriented socket. RFCOMM sockets emulate an RS-232 serial port.</p>
<p>To create a connection to a Bluetooth service, create a socket of the appropriate type and call <a href="qbluetoothsocket.html#connectToService">connectToService</a>() passing the Bluetooth address and port number. <a href="qbluetoothsocket.html">QBluetoothSocket</a> will emit the <a href="qbluetoothsocket.html#connected">connected</a>() signal when the connection is established.</p>
<p>If the <a href="qbluetoothserviceinfo.html#Protocol-enum">Protocol</a> is not supported on a platform, calling <a href="qbluetoothsocket.html#connectToService">connectToService</a>() will emit a <a href="qbluetoothsocket.html#SocketError-enum">UnsupportedProtocolError</a> error.</p>
<p><b>Note: </b><a href="qbluetoothsocket.html">QBluetoothSocket</a> does not support synchronous read and write operations. Functions such as waitForReadyRead() and waitForBytesWritten() are not implemented. I/O operations should be performed using readyRead(), read() and write().</p><p>On iOS, this class cannot be used because the platform does not expose an API which may permit access to <a href="qbluetoothsocket.html">QBluetoothSocket</a> related features.</p>
</div>
<!-- @@@QBluetoothSocket -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$SocketError$$$NoSocketError$$$UnknownSocketError$$$RemoteHostClosedError$$$HostNotFoundError$$$ServiceNotFoundError$$$NetworkError$$$UnsupportedProtocolError$$$OperationError -->
<h3 class="fn" id="SocketError-enum"><a name="SocketError-enum"></a>enum QBluetoothSocket::<span class="name">SocketError</span></h3>
<p>This enum describes Bluetooth socket error types.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::UnknownSocketError</code></td><td class="topAlign tblval"><code>QAbstractSocket::UnknownSocketError</code></td><td class="topAlign">An unknown error has occurred.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::NoSocketError</code></td><td class="topAlign tblval"><code>-2</code></td><td class="topAlign">No error. Used for testing.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::HostNotFoundError</code></td><td class="topAlign tblval"><code>QAbstractSocket::HostNotFoundError</code></td><td class="topAlign">Could not find the remote host.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::ServiceNotFoundError</code></td><td class="topAlign tblval"><code>QAbstractSocket::SocketAddressNotAvailableError</code></td><td class="topAlign">Could not find the service UUID on remote host.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::NetworkError</code></td><td class="topAlign tblval"><code>QAbstractSocket::NetworkError</code></td><td class="topAlign">Attempt to read or write from socket returned an error</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::UnsupportedProtocolError</code></td><td class="topAlign tblval"><code>8</code></td><td class="topAlign">The <a href="qbluetoothserviceinfo.html#Protocol-enum">Protocol</a> is not supported on this platform.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::OperationError</code></td><td class="topAlign tblval"><code>QAbstractSocket::OperationError</code></td><td class="topAlign">An operation was attempted while the socket was in a state that did not permit it.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::RemoteHostClosedError</code></td><td class="topAlign tblval"><code>QAbstractSocket::RemoteHostClosedError</code></td><td class="topAlign">The remote host closed the connection. This value was introduced by Qt 5.10.</td></tr>
</table></div>
<!-- @@@SocketError -->
<!-- $$$SocketState$$$UnconnectedState$$$ServiceLookupState$$$ConnectingState$$$ConnectedState$$$BoundState$$$ClosingState$$$ListeningState -->
<h3 class="fn" id="SocketState-enum"><a name="SocketState-enum"></a>enum QBluetoothSocket::<span class="name">SocketState</span></h3>
<p>This enum describes the state of the Bluetooth socket.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::UnconnectedState</code></td><td class="topAlign tblval"><code>QAbstractSocket::UnconnectedState</code></td><td class="topAlign">Socket is not connected.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::ServiceLookupState</code></td><td class="topAlign tblval"><code>QAbstractSocket::HostLookupState</code></td><td class="topAlign">Socket is querying connection parameters.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::ConnectingState</code></td><td class="topAlign tblval"><code>QAbstractSocket::ConnectingState</code></td><td class="topAlign">Socket is attempting to connect to a device.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::ConnectedState</code></td><td class="topAlign tblval"><code>QAbstractSocket::ConnectedState</code></td><td class="topAlign">Socket is connected to a device.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::BoundState</code></td><td class="topAlign tblval"><code>QAbstractSocket::BoundState</code></td><td class="topAlign">Socket is bound to a local address and port.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::ClosingState</code></td><td class="topAlign tblval"><code>QAbstractSocket::ClosingState</code></td><td class="topAlign">Socket is connected and will be closed once all pending data is written to the socket.</td></tr>
<tr><td class="topAlign"><code>QBluetoothSocket::ListeningState</code></td><td class="topAlign tblval"><code>QAbstractSocket::ListeningState</code></td><td class="topAlign">Socket is listening for incoming connections.</td></tr>
</table></div>
<!-- @@@SocketState -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QBluetoothSocket[overload1]$$$QBluetoothSocketQBluetoothServiceInfo::ProtocolQObject* -->
<h3 class="fn" id="QBluetoothSocket"><a name="QBluetoothSocket"></a>QBluetoothSocket::<span class="name">QBluetoothSocket</span>(<span class="type"><a href="qbluetoothserviceinfo.html#Protocol-enum">QBluetoothServiceInfo::Protocol</a></span> <i>socketType</i>, <span class="type">QObject</span> *<i>parent</i> = nullptr)</h3>
<p>Constructs a Bluetooth socket of <i>socketType</i> type, with <i>parent</i>.</p>
<!-- @@@QBluetoothSocket -->
<!-- $$$QBluetoothSocket$$$QBluetoothSocketQObject* -->
<h3 class="fn" id="QBluetoothSocket-1"><a name="QBluetoothSocket-1"></a>QBluetoothSocket::<span class="name">QBluetoothSocket</span>(<span class="type">QObject</span> *<i>parent</i> = nullptr)</h3>
<p>Constructs a Bluetooth socket with <i>parent</i>.</p>
<!-- @@@QBluetoothSocket -->
<!-- $$$~QBluetoothSocket[overload1]$$$~QBluetoothSocket -->
<h3 class="fn" id="dtor.QBluetoothSocket"><a name="dtor.QBluetoothSocket"></a><code>[virtual] </code>QBluetoothSocket::<span class="name">~QBluetoothSocket</span>()</h3>
<p>Destroys the Bluetooth socket.</p>
<!-- @@@~QBluetoothSocket -->
<!-- $$$abort[overload1]$$$abort -->
<h3 class="fn" id="abort"><a name="abort"></a><span class="type">void</span> QBluetoothSocket::<span class="name">abort</span>()</h3>
<p>Aborts the current connection and resets the socket. Unlike <a href="qbluetoothsocket.html#disconnectFromService">disconnectFromService</a>(), this function immediately closes the socket, discarding any pending data in the write buffer.</p>
<p><b>Note: </b>On Android, aborting the socket requires asynchronous interaction with Android threads. Therefore the associated <a href="qbluetoothsocket.html#disconnected">disconnected</a>() and <a href="qbluetoothsocket.html#stateChanged">stateChanged</a>() signals are delayed until the threads have finished the closure.</p><p><b>See also </b><a href="qbluetoothsocket.html#disconnectFromService">disconnectFromService</a>() and <a href="qbluetoothsocket.html#close">close</a>().</p>
<!-- @@@abort -->
<!-- $$$bytesAvailable[overload1]$$$bytesAvailable -->
<h3 class="fn" id="bytesAvailable"><a name="bytesAvailable"></a><code>[virtual] </code><span class="type">qint64</span> QBluetoothSocket::<span class="name">bytesAvailable</span>() const</h3>
<p>Returns the number of incoming bytes that are waiting to be read.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#bytesToWrite">bytesToWrite</a>() and read().</p>
<!-- @@@bytesAvailable -->
<!-- $$$bytesToWrite[overload1]$$$bytesToWrite -->
<h3 class="fn" id="bytesToWrite"><a name="bytesToWrite"></a><code>[virtual] </code><span class="type">qint64</span> QBluetoothSocket::<span class="name">bytesToWrite</span>() const</h3>
<p>Returns the number of bytes that are waiting to be written. The bytes are written when control goes back to the event loop.</p>
<!-- @@@bytesToWrite -->
<!-- $$$canReadLine[overload1]$$$canReadLine -->
<h3 class="fn" id="canReadLine"><a name="canReadLine"></a><code>[virtual] </code><span class="type">bool</span> QBluetoothSocket::<span class="name">canReadLine</span>() const</h3>
<p>Returns true if you can read at least one line from the device</p>
<!-- @@@canReadLine -->
<!-- $$$close[overload1]$$$close -->
<h3 class="fn" id="close"><a name="close"></a><code>[virtual] </code><span class="type">void</span> QBluetoothSocket::<span class="name">close</span>()</h3>
<p>Disconnects the socket's connection with the device.</p>
<p><b>Note: </b>On Android, closing the socket requires asynchronous interaction with Android threads. Therefore the associated <a href="qbluetoothsocket.html#disconnected">disconnected</a>() and <a href="qbluetoothsocket.html#stateChanged">stateChanged</a>() signals are delayed until the threads have finished the closure.</p><!-- @@@close -->
<!-- $$$connectToService[overload1]$$$connectToServiceconstQBluetoothServiceInfo&QIODevice::OpenMode -->
<h3 class="fn" id="connectToService"><a name="connectToService"></a><span class="type">void</span> QBluetoothSocket::<span class="name">connectToService</span>(const <span class="type"><a href="qbluetoothserviceinfo.html">QBluetoothServiceInfo</a></span> &amp;<i>service</i>, <span class="type">QIODevice::OpenMode</span> <i>openMode</i> = ReadWrite)</h3>
<p>Attempts to connect to the service described by <i>service</i>.</p>
<p>The socket is opened in the given <i>openMode</i>. The <a href="qbluetoothsocket.html#socketType">socketType</a>() is ignored if <i>service</i> specifies a differing <a href="qbluetoothserviceinfo.html#socketProtocol">QBluetoothServiceInfo::socketProtocol</a>().</p>
<p>The socket first enters <a href="qbluetoothsocket.html#SocketState-enum">ConnectingState</a> and attempts to connect to the device providing <i>service</i>. If a connection is established, <a href="qbluetoothsocket.html">QBluetoothSocket</a> enters <a href="qbluetoothsocket.html#SocketState-enum">ConnectedState</a> and emits <a href="qbluetoothsocket.html#connected">connected</a>().</p>
<p>At any point, the socket can emit <a href="qbluetoothsocket.html#error">error</a>() to signal that an error occurred.</p>
<p>Note that most platforms require a pairing prior to connecting to the remote device. Otherwise the connection process may fail.</p>
<p>On Android, only RFCOMM connections are possible. This function ignores any socket protocol indicator and assumes RFCOMM.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#state">state</a>() and <a href="qbluetoothsocket.html#disconnectFromService">disconnectFromService</a>().</p>
<!-- @@@connectToService -->
<!-- $$$connectToService$$$connectToServiceconstQBluetoothAddress&constQBluetoothUuid&QIODevice::OpenMode -->
<h3 class="fn" id="connectToService-1"><a name="connectToService-1"></a><span class="type">void</span> QBluetoothSocket::<span class="name">connectToService</span>(const <span class="type"><a href="qbluetoothaddress.html">QBluetoothAddress</a></span> &amp;<i>address</i>, const <span class="type"><a href="qbluetoothuuid.html">QBluetoothUuid</a></span> &amp;<i>uuid</i>, <span class="type">QIODevice::OpenMode</span> <i>openMode</i> = ReadWrite)</h3>
<p>Attempts to make a connection to the service identified by <i>uuid</i> on the device with address <i>address</i>.</p>
<p>The socket is opened in the given <i>openMode</i>.</p>
<p>For <a href="qtbluetooth-attribution-bluez.html">BlueZ</a>, the socket first enters the <a href="qbluetoothsocket.html#SocketState-enum">ServiceLookupState</a> and queries the connection parameters for <i>uuid</i>. If the service parameters are successfully retrieved the socket enters <a href="qbluetoothsocket.html#SocketState-enum">ConnectingState</a>, and attempts to connect to <i>address</i>. If a connection is established, <a href="qbluetoothsocket.html">QBluetoothSocket</a> enters <a href="qbluetoothsocket.html#SocketState-enum">ConnectedState</a> and emits <a href="qbluetoothsocket.html#connected">connected</a>().</p>
<p>On Android, the service connection can directly be established using the UUID of the remote service. Therefore the platform does not require the <a href="qbluetoothsocket.html#SocketState-enum">ServiceLookupState</a> and <a href="qbluetoothsocket.html#socketType">socketType</a>() is always set to <a href="qbluetoothserviceinfo.html#Protocol-enum">QBluetoothServiceInfo::RfcommProtocol</a>.</p>
<p>At any point, the socket can emit <a href="qbluetoothsocket.html#error">error</a>() to signal that an error occurred.</p>
<p>Note that most platforms require a pairing prior to connecting to the remote device. Otherwise the connection process may fail.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#state">state</a>() and <a href="qbluetoothsocket.html#disconnectFromService">disconnectFromService</a>().</p>
<!-- @@@connectToService -->
<!-- $$$connectToService$$$connectToServiceconstQBluetoothAddress&quint16QIODevice::OpenMode -->
<h3 class="fn" id="connectToService-2"><a name="connectToService-2"></a><span class="type">void</span> QBluetoothSocket::<span class="name">connectToService</span>(const <span class="type"><a href="qbluetoothaddress.html">QBluetoothAddress</a></span> &amp;<i>address</i>, <span class="type">quint16</span> <i>port</i>, <span class="type">QIODevice::OpenMode</span> <i>openMode</i> = ReadWrite)</h3>
<p>Attempts to make a connection with <i>address</i> on the given <i>port</i>.</p>
<p>The socket is opened in the given <i>openMode</i>.</p>
<p>The socket first enters <a href="qbluetoothsocket.html#SocketState-enum">ConnectingState</a>, and attempts to connect to <i>address</i>. If a connection is established, <a href="qbluetoothsocket.html">QBluetoothSocket</a> enters <a href="qbluetoothsocket.html#SocketState-enum">ConnectedState</a> and emits <a href="qbluetoothsocket.html#connected">connected</a>().</p>
<p>At any point, the socket can emit <a href="qbluetoothsocket.html#error">error</a>() to signal that an error occurred.</p>
<p>On Android and <a href="qtbluetooth-attribution-bluez.html">BlueZ</a> (version 5.46 or above), a connection to a service can not be established using a port. Calling this function will emit a <a href="qbluetoothsocket.html#SocketError-enum">ServiceNotFoundError</a>.</p>
<p>Note that most platforms require a pairing prior to connecting to the remote device. Otherwise the connection process may fail.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#state">state</a>() and <a href="qbluetoothsocket.html#disconnectFromService">disconnectFromService</a>().</p>
<!-- @@@connectToService -->
<!-- $$$connected[overload1]$$$connected -->
<h3 class="fn" id="connected"><a name="connected"></a><code>[signal] </code><span class="type">void</span> QBluetoothSocket::<span class="name">connected</span>()</h3>
<p>This signal is emitted when a connection is established.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#SocketState-enum">QBluetoothSocket::ConnectedState</a> and <a href="qbluetoothsocket.html#stateChanged">stateChanged</a>().</p>
<!-- @@@connected -->
<!-- $$$disconnectFromService[overload1]$$$disconnectFromService -->
<h3 class="fn" id="disconnectFromService"><a name="disconnectFromService"></a><span class="type">void</span> QBluetoothSocket::<span class="name">disconnectFromService</span>()</h3>
<p>Attempts to close the socket. If there is pending data waiting to be written <a href="qbluetoothsocket.html">QBluetoothSocket</a> will enter <a href="qbluetoothsocket.html#SocketState-enum">ClosingState</a> and wait until all data has been written. Eventually, it will enter <a href="qbluetoothsocket.html#SocketState-enum">UnconnectedState</a> and emit the <a href="qbluetoothsocket.html#disconnected">disconnected</a>() signal.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#connectToService">connectToService</a>().</p>
<!-- @@@disconnectFromService -->
<!-- $$$disconnected[overload1]$$$disconnected -->
<h3 class="fn" id="disconnected"><a name="disconnected"></a><code>[signal] </code><span class="type">void</span> QBluetoothSocket::<span class="name">disconnected</span>()</h3>
<p>This signal is emitted when the socket is disconnected.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#SocketState-enum">QBluetoothSocket::UnconnectedState</a> and <a href="qbluetoothsocket.html#stateChanged">stateChanged</a>().</p>
<!-- @@@disconnected -->
<!-- $$$doDeviceDiscovery[overload1]$$$doDeviceDiscoveryconstQBluetoothServiceInfo&QIODevice::OpenMode -->
<h3 class="fn" id="doDeviceDiscovery"><a name="doDeviceDiscovery"></a><code>[protected] </code><span class="type">void</span> QBluetoothSocket::<span class="name">doDeviceDiscovery</span>(const <span class="type"><a href="qbluetoothserviceinfo.html">QBluetoothServiceInfo</a></span> &amp;<i>service</i>, <span class="type">QIODevice::OpenMode</span> <i>openMode</i>)</h3>
<p>Start device discovery for <i>service</i> and open the socket with <i>openMode</i>. If the socket is created with a service uuid device address, use service discovery to find the port number to connect to.</p>
<!-- @@@doDeviceDiscovery -->
<!-- $$$error[overload1]$$$error -->
<h3 class="fn" id="error"><a name="error"></a><span class="type"><a href="qbluetoothsocket.html#SocketError-enum">QBluetoothSocket::SocketError</a></span> QBluetoothSocket::<span class="name">error</span>() const</h3>
<p>Returns the last error.</p>
<!-- @@@error -->
<!-- $$$error$$$errorQBluetoothSocket::SocketError -->
<h3 class="fn" id="error-1"><a name="error-1"></a><code>[signal] </code><span class="type">void</span> QBluetoothSocket::<span class="name">error</span>(<span class="type"><a href="qbluetoothsocket.html#SocketError-enum">QBluetoothSocket::SocketError</a></span> <i>error</i>)</h3>
<p>This signal is emitted when an <i>error</i> occurs.</p>
<p><b>Note:</b> Signal <i>error</i> is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:<pre class="cpp">

  connect(bluetoothSocket<span class="operator">,</span> <span class="type">QOverload</span><span class="operator">&lt;</span><span class="type"><a href="qbluetoothsocket.html#QBluetoothSocket">QBluetoothSocket</a></span><span class="operator">::</span>SocketError<span class="operator">&gt;</span><span class="operator">::</span>of(<span class="operator">&amp;</span><span class="type"><a href="qbluetoothsocket.html#QBluetoothSocket">QBluetoothSocket</a></span><span class="operator">::</span>error)<span class="operator">,</span>
      <span class="operator">[</span><span class="operator">=</span><span class="operator">]</span>(<span class="type"><a href="qbluetoothsocket.html#QBluetoothSocket">QBluetoothSocket</a></span><span class="operator">::</span>SocketError error){ <span class="comment">/* ... */</span> });

</pre>
<p><b>See also </b><a href="qbluetoothsocket.html#error">error</a>().</p>
<!-- @@@error -->
<!-- $$$errorString[overload1]$$$errorString -->
<h3 class="fn" id="errorString"><a name="errorString"></a><span class="type">QString</span> QBluetoothSocket::<span class="name">errorString</span>() const</h3>
<p>Returns a user displayable text string for the error.</p>
<!-- @@@errorString -->
<!-- $$$isSequential[overload1]$$$isSequential -->
<h3 class="fn" id="isSequential"><a name="isSequential"></a><code>[virtual] </code><span class="type">bool</span> QBluetoothSocket::<span class="name">isSequential</span>() const</h3>
<!-- @@@isSequential -->
<!-- $$$localAddress[overload1]$$$localAddress -->
<h3 class="fn" id="localAddress"><a name="localAddress"></a><span class="type"><a href="qbluetoothaddress.html">QBluetoothAddress</a></span> QBluetoothSocket::<span class="name">localAddress</span>() const</h3>
<p>Returns the address of the local device.</p>
<p>Although some platforms may differ the socket must generally be connected to guarantee the return of a valid address. In particular, this is true when dealing with platforms that support multiple local Bluetooth adapters.</p>
<!-- @@@localAddress -->
<!-- $$$localName[overload1]$$$localName -->
<h3 class="fn" id="localName"><a name="localName"></a><span class="type">QString</span> QBluetoothSocket::<span class="name">localName</span>() const</h3>
<p>Returns the name of the local device.</p>
<p>Although some platforms may differ the socket must generally be connected to guarantee the return of a valid name. In particular, this is true when dealing with platforms that support multiple local Bluetooth adapters.</p>
<!-- @@@localName -->
<!-- $$$localPort[overload1]$$$localPort -->
<h3 class="fn" id="localPort"><a name="localPort"></a><span class="type">quint16</span> QBluetoothSocket::<span class="name">localPort</span>() const</h3>
<p>Returns the port number of the local socket if available, otherwise returns 0. Although some platforms may differ the socket must generally be connected to guarantee the return of a valid port number.</p>
<p>On Android and macOS, this feature is not supported and returns 0.</p>
<!-- @@@localPort -->
<!-- $$$peerAddress[overload1]$$$peerAddress -->
<h3 class="fn" id="peerAddress"><a name="peerAddress"></a><span class="type"><a href="qbluetoothaddress.html">QBluetoothAddress</a></span> QBluetoothSocket::<span class="name">peerAddress</span>() const</h3>
<p>Returns the address of the peer device.</p>
<!-- @@@peerAddress -->
<!-- $$$peerName[overload1]$$$peerName -->
<h3 class="fn" id="peerName"><a name="peerName"></a><span class="type">QString</span> QBluetoothSocket::<span class="name">peerName</span>() const</h3>
<p>Returns the name of the peer device.</p>
<!-- @@@peerName -->
<!-- $$$peerPort[overload1]$$$peerPort -->
<h3 class="fn" id="peerPort"><a name="peerPort"></a><span class="type">quint16</span> QBluetoothSocket::<span class="name">peerPort</span>() const</h3>
<p>Return the port number of the peer socket if available, otherwise returns 0. On Android, this feature is not supported.</p>
<!-- @@@peerPort -->
<!-- $$$preferredSecurityFlags[overload1]$$$preferredSecurityFlags -->
<h3 class="fn" id="preferredSecurityFlags"><a name="preferredSecurityFlags"></a><span class="type"><a href="qbluetooth.html#Security-enum">QBluetooth::SecurityFlags</a></span> QBluetoothSocket::<span class="name">preferredSecurityFlags</span>() const</h3>
<p>Returns the security parameters used for the initial connection attempt.</p>
<p>The security parameters may be renegotiated between the two parties during or after the connection has been established. If such a change happens it is not reflected in the value of this flag.</p>
<p>On macOS, this flag is always set to <a href="qbluetooth.html#Security-enum">QBluetooth::Secure</a>.</p>
<p>This function was introduced in  Qt 5.6.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#setPreferredSecurityFlags">setPreferredSecurityFlags</a>().</p>
<!-- @@@preferredSecurityFlags -->
<!-- $$$readData[overload1]$$$readDatachar*qint64 -->
<h3 class="fn" id="readData"><a name="readData"></a><code>[virtual protected] </code><span class="type">qint64</span> QBluetoothSocket::<span class="name">readData</span>(<span class="type">char</span> *<i>data</i>, <span class="type">qint64</span> <i>maxSize</i>)</h3>
<!-- @@@readData -->
<!-- $$$setPreferredSecurityFlags[overload1]$$$setPreferredSecurityFlagsQBluetooth::SecurityFlags -->
<h3 class="fn" id="setPreferredSecurityFlags"><a name="setPreferredSecurityFlags"></a><span class="type">void</span> QBluetoothSocket::<span class="name">setPreferredSecurityFlags</span>(<span class="type"><a href="qbluetooth.html#Security-enum">QBluetooth::SecurityFlags</a></span> <i>flags</i>)</h3>
<p>Sets the preferred security parameter for the connection attempt to <i>flags</i>. This value is incorporated when calling <a href="qbluetoothsocket.html#connectToService">connectToService</a>(). Therefore it is required to reconnect to change this parameter for an existing connection.</p>
<p>On Bluez this property is set to <a href="qbluetooth.html#Security-enum">QBluetooth::Authorization</a> by default.</p>
<p>On macOS, this value is ignored as the platform does not permit access to the security parameter of the socket. By default the platform prefers secure/encrypted connections though and therefore this function always returns <a href="qbluetooth.html#Security-enum">QBluetooth::Secure</a>.</p>
<p>Android only supports two levels of security (secure and non-secure). If this flag is set to <a href="qbluetooth.html#Security-enum">QBluetooth::NoSecurity</a> the socket object will not employ any authentication or encryption. Any other security flag combination will trigger a secure Bluetooth connection. This flag is set to <a href="qbluetooth.html#Security-enum">QBluetooth::Secure</a> by default.</p>
<p><b>Note: </b>A secure connection requires a pairing between the two devices. On some platforms, the pairing is automatically initiated during the establishment of the connection. Other platforms require the application to manually trigger the pairing before attempting to connect.</p><p>This function was introduced in  Qt 5.6.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#preferredSecurityFlags">preferredSecurityFlags</a>().</p>
<!-- @@@setPreferredSecurityFlags -->
<!-- $$$setSocketDescriptor[overload1]$$$setSocketDescriptorintQBluetoothServiceInfo::ProtocolQBluetoothSocket::SocketStateQIODevice::OpenMode -->
<h3 class="fn" id="setSocketDescriptor"><a name="setSocketDescriptor"></a><span class="type">bool</span> QBluetoothSocket::<span class="name">setSocketDescriptor</span>(<span class="type">int</span> <i>socketDescriptor</i>, <span class="type"><a href="qbluetoothserviceinfo.html#Protocol-enum">QBluetoothServiceInfo::Protocol</a></span> <i>socketType</i>, <span class="type"><a href="qbluetoothsocket.html#SocketState-enum">QBluetoothSocket::SocketState</a></span> <i>socketState</i> = ConnectedState, <span class="type">QIODevice::OpenMode</span> <i>openMode</i> = ReadWrite)</h3>
<p>Set the socket to use <i>socketDescriptor</i> with a type of <i>socketType</i>, which is in state, <i>socketState</i>, and mode, <i>openMode</i>.</p>
<p>Returns true on success</p>
<p><b>See also </b><a href="qbluetoothsocket.html#socketDescriptor">socketDescriptor</a>().</p>
<!-- @@@setSocketDescriptor -->
<!-- $$$setSocketError[overload1]$$$setSocketErrorQBluetoothSocket::SocketError -->
<h3 class="fn" id="setSocketError"><a name="setSocketError"></a><code>[protected] </code><span class="type">void</span> QBluetoothSocket::<span class="name">setSocketError</span>(<span class="type"><a href="qbluetoothsocket.html#SocketError-enum">QBluetoothSocket::SocketError</a></span> <i>error_</i>)</h3>
<p>Sets the type of error that last occurred to <i>error_</i>.</p>
<!-- @@@setSocketError -->
<!-- $$$setSocketState[overload1]$$$setSocketStateQBluetoothSocket::SocketState -->
<h3 class="fn" id="setSocketState"><a name="setSocketState"></a><code>[protected] </code><span class="type">void</span> QBluetoothSocket::<span class="name">setSocketState</span>(<span class="type"><a href="qbluetoothsocket.html#SocketState-enum">QBluetoothSocket::SocketState</a></span> <i>state</i>)</h3>
<p>Sets the socket state to <i>state</i>.</p>
<!-- @@@setSocketState -->
<!-- $$$socketDescriptor[overload1]$$$socketDescriptor -->
<h3 class="fn" id="socketDescriptor"><a name="socketDescriptor"></a><span class="type">int</span> QBluetoothSocket::<span class="name">socketDescriptor</span>() const</h3>
<p>Returns the platform-specific socket descriptor, if available. This function returns -1 if the descriptor is not available or an error has occurred.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#setSocketDescriptor">setSocketDescriptor</a>().</p>
<!-- @@@socketDescriptor -->
<!-- $$$socketType[overload1]$$$socketType -->
<h3 class="fn" id="socketType"><a name="socketType"></a><span class="type"><a href="qbluetoothserviceinfo.html#Protocol-enum">QBluetoothServiceInfo::Protocol</a></span> QBluetoothSocket::<span class="name">socketType</span>() const</h3>
<p>Returns the socket type. The socket automatically adjusts to the protocol offered by the remote service.</p>
<p>Android only support <a href="qbluetoothserviceinfo.html#Protocol-enum">RFCOMM</a> based sockets.</p>
<!-- @@@socketType -->
<!-- $$$state[overload1]$$$state -->
<h3 class="fn" id="state"><a name="state"></a><span class="type"><a href="qbluetoothsocket.html#SocketState-enum">QBluetoothSocket::SocketState</a></span> QBluetoothSocket::<span class="name">state</span>() const</h3>
<p>Returns the current state of the socket.</p>
<!-- @@@state -->
<!-- $$$stateChanged[overload1]$$$stateChangedQBluetoothSocket::SocketState -->
<h3 class="fn" id="stateChanged"><a name="stateChanged"></a><code>[signal] </code><span class="type">void</span> QBluetoothSocket::<span class="name">stateChanged</span>(<span class="type"><a href="qbluetoothsocket.html#SocketState-enum">QBluetoothSocket::SocketState</a></span> <i>state</i>)</h3>
<p>This signal is emitted when the socket state changes to <i>state</i>.</p>
<p><b>See also </b><a href="qbluetoothsocket.html#connected">connected</a>(), <a href="qbluetoothsocket.html#disconnected">disconnected</a>(), <a href="qbluetoothsocket.html#state">state</a>(), and <a href="qbluetoothsocket.html#SocketState-enum">QBluetoothSocket::SocketState</a>.</p>
<!-- @@@stateChanged -->
<!-- $$$writeData[overload1]$$$writeDataconstchar*qint64 -->
<h3 class="fn" id="writeData"><a name="writeData"></a><code>[virtual protected] </code><span class="type">qint64</span> QBluetoothSocket::<span class="name">writeData</span>(const <span class="type">char</span> *<i>data</i>, <span class="type">qint64</span> <i>maxSize</i>)</h3>
<!-- @@@writeData -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 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>