-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
75 lines (65 loc) · 2.04 KB
/
Copy pathmainwindow.cpp
File metadata and controls
75 lines (65 loc) · 2.04 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
_server = nullptr;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_btnStartServer_clicked()
{
if(_server == nullptr){
auto port = ui->spnServerPort->value();
auto ip = ui->InIPAddress->text();
auto period = ui->spnPeriod->value();
_server = new MyTCPserver(ip,port,period);
connect(_server, &MyTCPserver::newClientConnected,this, &MainWindow::newClient_connected);
connect(_server, &MyTCPserver::dataReceived,this, &MainWindow::clientDataReceived);
connect(_server, &MyTCPserver::clientDisconnect,this, &MainWindow::clientDisconnected);
if(_server->isStarted()){
ui->btnStartServer->setText("Stop Server");
ui->lblConnectionStatus->setProperty("state","0");
style()->polish(ui->lblConnectionStatus);
}else{
qDebug() << "Failed to start the server.";
}
}else{
_server->stopServer();
// delete _server;
_server = nullptr;
ui->btnStartServer->setText("Start Server");
ui->lblConnectionStatus->setProperty("state","1");
style()->polish(ui->lblConnectionStatus);
}
}
void MainWindow::newClient_connected()
{
ui->lstConsole->addItem("New Client connected");
}
void MainWindow::clientDisconnected()
{
ui->lstConsole->addItem("Client Disconnected");
}
void MainWindow::clientDataReceived(QString message)
{
ui->lstConsole->addItem(message);
}
void MainWindow::on_InIPAddress_textChanged(const QString &arg1)
{
QString state = "0";
if(arg1 == "..."){
state = "";
}else{
QHostAddress address(arg1);
if(QAbstractSocket::IPv4Protocol == address.protocol()){
state = "1";
}
}
ui->InIPAddress->setProperty("state",state);
style()->polish(ui->InIPAddress);
}