-
Notifications
You must be signed in to change notification settings - Fork 0
/
qmlclient.h
55 lines (41 loc) · 1.38 KB
/
qmlclient.h
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
#ifndef QMLCLIENT_H
#define QMLCLIENT_H
#include <QObject>
#include "qmqtt.h"
class QmlClient : public QObject
{
Q_OBJECT
Q_PROPERTY(QString hostip READ hostString WRITE setHostString NOTIFY hostStringChanged)
Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged)
Q_PROPERTY(QString subscribeTopic READ subscribeTopic WRITE setSubscribeTopic NOTIFY subscribeTopicChanged)
public:
explicit QmlClient(QObject *parent = nullptr);
QString hostString() const;
void setHostString(const QString host);
int port() const;
void setPort(const int port);
bool isConnected() const;
void setIsConnected(const bool status);
QString subscribeTopic() const;
void setSubscribeTopic(const QString topic);
signals:
void hostStringChanged();
void portChanged();
void isConnectedChanged();
void subscribeTopicChanged();
void newMessage(QString topic, QString message);
public slots:
void publishMsg(const quint16 id, const QString &topic, const QString &message);
// void connected();
void subscribed(QString topic);
void received(QMQTT::Message message);
private slots:
void setConnectedTrue();
void setConnectedFalse();
private:
QMQTT::Client *_client;
bool _connected;
QString _currnetTopic = "/#";
};
#endif // QMLCLIENT_H