diff options
author | Liang Qi <liang.qi@qt.io> | 2017-09-20 11:38:57 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-09-20 11:38:57 +0200 |
commit | ba755c28ea0cd35cfa9d8c77ef7f2c61437ad25b (patch) | |
tree | 3379cee43d6acae95312e51e6cd05c3c4198a95e /examples/webchannel/chatserver-cpp | |
parent | 749951c19cbb7d301bed20f24d16dd4e713485c2 (diff) | |
parent | d84318e98aa3cbac11b4f95b3581e95aab96a34a (diff) | |
download | qtwebchannel-ba755c28ea0cd35cfa9d8c77ef7f2c61437ad25b.tar.gz |
Merge remote-tracking branch 'origin/5.9' into 5.10v5.10.0-beta3v5.10.0-beta2v5.10.0-beta1
Change-Id: I54f0bcd46ffb496156e46d723275cdd29601e45c
Diffstat (limited to 'examples/webchannel/chatserver-cpp')
-rw-r--r-- | examples/webchannel/chatserver-cpp/chatserver.cpp | 22 | ||||
-rw-r--r-- | examples/webchannel/chatserver-cpp/chatserver.h | 22 | ||||
-rw-r--r-- | examples/webchannel/chatserver-cpp/main.cpp | 4 |
3 files changed, 21 insertions, 27 deletions
diff --git a/examples/webchannel/chatserver-cpp/chatserver.cpp b/examples/webchannel/chatserver-cpp/chatserver.cpp index 74da4c3..1025c80 100644 --- a/examples/webchannel/chatserver-cpp/chatserver.cpp +++ b/examples/webchannel/chatserver-cpp/chatserver.cpp @@ -50,30 +50,28 @@ #include "chatserver.h" -#include <QtCore/QDebug> -#include <QTimer> +#include <QDebug> #include <QTime> - -QT_BEGIN_NAMESPACE +#include <QTimer> ChatServer::ChatServer(QObject *parent) : QObject(parent) { - QTimer* t = new QTimer(this); - connect(t, SIGNAL(timeout()), this, SLOT(sendKeepAlive())); + QTimer *t = new QTimer(this); + connect(t, &QTimer::timeout, this, &ChatServer::sendKeepAlive); t->start(10000); m_keepAliveCheckTimer = new QTimer(this); m_keepAliveCheckTimer->setSingleShot(true); m_keepAliveCheckTimer->setInterval(2000); - connect(m_keepAliveCheckTimer, SIGNAL(timeout()), this, SLOT(checkKeepAliveResponses())); + connect(m_keepAliveCheckTimer, &QTimer::timeout, this, &ChatServer::checkKeepAliveResponses); } ChatServer::~ChatServer() {} -bool ChatServer::login(const QString& userName) +bool ChatServer::login(const QString &userName) { //stop keepAliveCheck, when a new user logged in if (m_keepAliveCheckTimer->isActive()) { @@ -93,7 +91,7 @@ bool ChatServer::login(const QString& userName) return true; } -bool ChatServer::logout(const QString& userName) +bool ChatServer::logout(const QString &userName) { if (!m_userList.contains(userName)) { return false; @@ -105,7 +103,7 @@ bool ChatServer::logout(const QString& userName) } } -bool ChatServer::sendMessage(const QString& user, const QString& msg) +bool ChatServer::sendMessage(const QString &user, const QString &msg) { if (m_userList.contains(user)) { emit newMessage(QTime::currentTime().toString("HH:mm:ss"), user, msg); @@ -130,7 +128,7 @@ void ChatServer::checkKeepAliveResponses() emit userListChanged(); } -void ChatServer::keepAliveResponse(const QString& user) +void ChatServer::keepAliveResponse(const QString &user) { m_stillAliveUsers.append(user); } @@ -140,5 +138,3 @@ QStringList ChatServer::userList() const { return m_userList; } - -QT_END_NAMESPACE diff --git a/examples/webchannel/chatserver-cpp/chatserver.h b/examples/webchannel/chatserver-cpp/chatserver.h index 20f0928..9bc8026 100644 --- a/examples/webchannel/chatserver-cpp/chatserver.h +++ b/examples/webchannel/chatserver-cpp/chatserver.h @@ -48,15 +48,15 @@ ** ****************************************************************************/ -#ifndef ChatServer_H -#define ChatServer_H +#ifndef CHATSERVER_H +#define CHATSERVER_H #include <QObject> #include <QStringList> QT_BEGIN_NAMESPACE - class QTimer; +QT_END_NAMESPACE class ChatServer : public QObject { @@ -65,22 +65,22 @@ class ChatServer : public QObject Q_PROPERTY(QStringList userList READ userList NOTIFY userListChanged) public: - explicit ChatServer(QObject *parent = 0); + explicit ChatServer(QObject *parent = nullptr); virtual ~ChatServer(); public: //a user logs in with the given username - Q_INVOKABLE bool login(const QString& 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); + 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); + 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); + Q_INVOKABLE void keepAliveResponse(const QString &user); QStringList userList() const; @@ -97,9 +97,7 @@ signals: private: QStringList m_userList; QStringList m_stillAliveUsers; - QTimer* m_keepAliveCheckTimer; + QTimer *m_keepAliveCheckTimer; }; -QT_END_NAMESPACE - -#endif // ChatServer_H +#endif // CHATSERVER_H diff --git a/examples/webchannel/chatserver-cpp/main.cpp b/examples/webchannel/chatserver-cpp/main.cpp index ea27e87..9e025ac 100644 --- a/examples/webchannel/chatserver-cpp/main.cpp +++ b/examples/webchannel/chatserver-cpp/main.cpp @@ -48,14 +48,14 @@ ** ****************************************************************************/ -#include "qwebchannel.h" #include "chatserver.h" #include "../shared/websocketclientwrapper.h" #include "../shared/websockettransport.h" -#include <QtWebSockets/QWebSocketServer> #include <QCoreApplication> +#include <QWebChannel> +#include <QWebSocketServer> int main(int argc, char** argv) { |