Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qbluetoothsocket.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QBLUETOOTHSOCKET_H
5#define QBLUETOOTHSOCKET_H
6
7#include <QtBluetooth/qtbluetoothglobal.h>
8
9#include <QtBluetooth/qbluetooth.h>
10#include <QtBluetooth/qbluetoothaddress.h>
11#include <QtBluetooth/qbluetoothuuid.h>
12#include <QtBluetooth/qbluetoothserviceinfo.h>
13
14#include <QtCore/qiodevice.h>
15
17
18
20
21class Q_BLUETOOTH_EXPORT QBluetoothSocket : public QIODevice
22{
24
25 Q_DECLARE_PRIVATE(QBluetoothSocketBase)
26
27 friend class QBluetoothServer;
29 friend class QBluetoothSocketPrivateDarwin;
34 friend class QBluetoothSocketPrivateWin;
36
37public:
38
39 enum class SocketState {
40 UnconnectedState,
41 ServiceLookupState,
42 ConnectingState,
43 ConnectedState,
44 BoundState,
45 ClosingState,
46 ListeningState
47 };
48 Q_ENUM(SocketState)
49
50 enum class SocketError {
51 NoSocketError,
52 UnknownSocketError,
53 RemoteHostClosedError,
54 HostNotFoundError,
55 ServiceNotFoundError,
56 NetworkError,
57 UnsupportedProtocolError,
58 OperationError,
59 MissingPermissionsError
60 };
61 Q_ENUM(SocketError)
62
63 explicit QBluetoothSocket(QBluetoothServiceInfo::Protocol socketType, QObject *parent = nullptr); // create socket of type socketType
64 explicit QBluetoothSocket(QObject *parent = nullptr); // create a blank socket
65 virtual ~QBluetoothSocket();
66
67 void abort();
68
69 void close() override;
70
71 bool isSequential() const override;
72
73 qint64 bytesAvailable() const override;
74 qint64 bytesToWrite() const override;
75
76 bool canReadLine() const override;
77
78 void connectToService(const QBluetoothServiceInfo &service, OpenMode openMode = ReadWrite);
79 void connectToService(const QBluetoothAddress &address, const QBluetoothUuid &uuid, OpenMode openMode = ReadWrite);
80 void connectToService(const QBluetoothAddress &address, quint16 port, OpenMode openMode = ReadWrite);
82 OpenMode mode = ReadWrite)
83 {
84 connectToService(address, QBluetoothUuid(uuid), mode);
85 }
86 void disconnectFromService();
87
88 //bool flush();
89 //bool isValid() const;
90
91 QString localName() const;
92 QBluetoothAddress localAddress() const;
93 quint16 localPort() const;
94
95 QString peerName() const;
96 QBluetoothAddress peerAddress() const;
97 quint16 peerPort() const;
98 //QBluetoothServiceInfo peerService() const;
99
100 //qint64 readBufferSize() const;
101 //void setReadBufferSize(qint64 size);
102
103 bool setSocketDescriptor(int socketDescriptor, QBluetoothServiceInfo::Protocol socketType,
104 SocketState socketState = SocketState::ConnectedState,
105 OpenMode openMode = ReadWrite);
106 int socketDescriptor() const;
107
109 SocketState state() const;
110 SocketError error() const;
111 QString errorString() const;
112
113 //bool waitForConnected(int msecs = 30000);
114 //bool waitForDisconnected(int msecs = 30000);
115 //virtual bool waitForReadyRead(int msecs = 30000);
116
117 void setPreferredSecurityFlags(QBluetooth::SecurityFlags flags);
118 QBluetooth::SecurityFlags preferredSecurityFlags() const;
119
121 void connected();
125
126protected:
127 qint64 readData(char *data, qint64 maxSize) override;
128 qint64 writeData(const char *data, qint64 maxSize) override;
129
130 void setSocketState(SocketState state);
131 void setSocketError(SocketError error);
132
133 void doDeviceDiscovery(const QBluetoothServiceInfo &service, OpenMode openMode);
134
135private Q_SLOTS:
136 void serviceDiscovered(const QBluetoothServiceInfo &service);
137 void discoveryFinished();
138
139
140protected:
141#if QT_CONFIG(bluez)
142 //evil hack to enable QBluetoothServer on Bluez to set the desired d_ptr
145 QObject *parent = nullptr);
146#endif
147
149
150private:
152};
153
154
156
157#endif
\inmodule QtBluetooth
\inmodule QtBluetooth
\inmodule QtBluetooth
Protocol
This enum describes the socket protocol used by the service.
\inmodule QtBluetooth
void connectToService(const QBluetoothAddress &address, QBluetoothUuid::ServiceClassUuid uuid, OpenMode mode=ReadWrite)
void connected()
This signal is emitted when a connection is established.
void stateChanged(QBluetoothSocket::SocketState state)
This signal is emitted when the socket state changes to state.
void errorOccurred(QBluetoothSocket::SocketError error)
This signal is emitted when an error occurs.
QBluetoothSocketBasePrivate * d_ptr
SocketState
This enum describes the state of the Bluetooth socket.
SocketError
This enum describes Bluetooth socket error types.
void disconnected()
This signal is emitted when the socket is disconnected.
\inmodule QtBluetooth
ServiceClassUuid
This enum is a convienience type for Bluetooth service class and profile UUIDs.
\inmodule QtCore \reentrant
Definition qiodevice.h:34
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
virtual qint64 writeData(const char *data, qint64 len)=0
Writes up to maxSize bytes from data to the device.
virtual qint64 bytesToWrite() const
For buffered devices, this function returns the number of bytes waiting to be written.
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false.
\inmodule QtCore
Definition qobject.h:90
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
else opt state
[0]
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
EGLOutputPortEXT port
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
GLenum mode
GLbitfield flags
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
#define Q_ENUM(x)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
unsigned short quint16
Definition qtypes.h:43
long long qint64
Definition qtypes.h:55
QByteArray readData()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent