-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatserver.h
56 lines (41 loc) · 1.31 KB
/
chatserver.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
56
#ifndef CHATSERVER_H
#define CHATSERVER_H
#include <QObject>
#include <QStringList>
class QTimer;
class ChatServer : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList userList READ userList NOTIFY userListChanged)
public:
explicit ChatServer(QObject *parent = nullptr);
virtual ~ChatServer();
public:
//a user logs in with the given username
Q_INVOKABLE bool login(const QString &userName);
//the user logs out, will be removed from userlist immediately
Q_INVOKABLE bool logout(const QString &userName);
//a user sends a message to all other users
Q_INVOKABLE bool sendMessage(const QString &user, const QString &msg);
//response of the keep alive signal from a client.
// This is used to detect disconnects.
Q_INVOKABLE void keepAliveResponse(const QString &user);
// 由JS端调用的元函数
Q_INVOKABLE void test1();
QStringList userList() const;
protected slots:
void sendKeepAlive();
void checkKeepAliveResponses();
signals:
void newMessage(QString time, QString user, QString msg);
void keepAlive();
void userListChanged();
void userCountChanged();
// 触发JS端函数的信号
void test2();
private:
QStringList m_userList;
QStringList m_stillAliveUsers;
QTimer *m_keepAliveCheckTimer;
};
#endif // CHATSERVER_H