chatserver.h Example File
chatserver-cpp/chatserver.h
#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:
Q_INVOKABLE bool login(const QString &userName);
Q_INVOKABLE bool logout(const QString &userName);
Q_INVOKABLE bool sendMessage(const QString &user, const QString &msg);
Q_INVOKABLE void keepAliveResponse(const QString &user);
QStringList userList() const;
protected slots:
void sendKeepAlive();
void checkKeepAliveResponses();
signals:
void newMessage(QString time, QString user, QString msg);
void keepAlive();
void userListChanged();
void userCountChanged();
private:
QStringList m_userList;
QStringList m_stillAliveUsers;
QTimer *m_keepAliveCheckTimer;
};
#endif // CHATSERVER_H