48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
// Copyright (C) 2017 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
#ifndef CHATCLIENT_H
|
|
#define CHATCLIENT_H
|
|
|
|
#include <QtCore/qobject.h>
|
|
|
|
#include <QtBluetooth/qbluetoothserviceinfo.h>
|
|
#include <QtBluetooth/qbluetoothsocket.h>
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QBluetoothSocket)
|
|
|
|
QT_USE_NAMESPACE
|
|
|
|
//! [declaration]
|
|
class ChatClient : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ChatClient(QObject *parent = nullptr);
|
|
~ChatClient();
|
|
|
|
void startClient(const QBluetoothServiceInfo &remoteService);
|
|
void stopClient();
|
|
|
|
public slots:
|
|
void sendMessage(const QString &message);
|
|
|
|
signals:
|
|
void messageReceived(const QString &sender, const QString &message);
|
|
void connected(const QString &name);
|
|
void disconnected();
|
|
void socketErrorOccurred(const QString &errorString);
|
|
|
|
private slots:
|
|
void readSocket();
|
|
void connected();
|
|
void onSocketErrorOccurred(QBluetoothSocket::SocketError);
|
|
|
|
private:
|
|
QBluetoothSocket *socket = nullptr;
|
|
};
|
|
//! [declaration]
|
|
|
|
#endif // CHATCLIENT_H
|