forked from umarbiliyamin/AppDevExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.cpp
More file actions
executable file
·48 lines (42 loc) · 1.25 KB
/
Copy pathApplication.cpp
File metadata and controls
executable file
·48 lines (42 loc) · 1.25 KB
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
#include "Application.h"
#include <QDataStream>
Application::Application(int argc, char *argv[], SocketServer &server, SocketClient &client)
: QCoreApplication(argc,argv), server(server), client(client), counter(0)
{
connect(&client, &SocketClient::dataReady, this, &Application::clientDataReady);
connect(&server, &SocketServer::dataReady, this, &Application::serverDataReady);
connect(&timer, &QTimer::timeout, this, &Application::tick);
}
void Application::clientDataReady(QDataStream& inStream)
{
QString text;
inStream >> text;
qWarning() << "Message received on the client socket: " << text;
}
void Application::serverDataReady(QDataStream& inStream)
{
QString text;
inStream >> text;
qWarning() << "Message received on the server socket: " << text;
if (text == "What's up, Doc?")
{
server.send("Everything OK.");
}
}
void Application::startSending()
{
timer.start(1000);
}
void Application::tick()
{
qDebug() << "Application::tick called";
counter++;
if (counter > 10)
{
qDebug() << "The tick executed 10 times, demo is ending.";
// The QCoreApplication class has exit() method.
this->exit(0);
return;
}
client.send(QString("What's up, Doc?"));
}