-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcpportview.cpp
More file actions
116 lines (99 loc) · 2.67 KB
/
Copy pathtcpportview.cpp
File metadata and controls
116 lines (99 loc) · 2.67 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "tcpportview.h"
#include "ui_tcpportview.h"
#include <QDebug>
#include <QThread>
#include <QHostAddress>
#include <QBuffer>
/**
* @brief Class constructor
* @param parent
*/
TcpPortView::TcpPortView(QWidget *parent) :
QWidget(parent), ui(new Ui::TcpPortView)
{
ui->setupUi(this);
tcpClient = new TcpClient;
threadTcpPort = new QThread;
threadTcpPort->setObjectName("threadTcpPort");
tcpClient->moveToThread(threadTcpPort);
QObject::connect(threadTcpPort, &QThread::started,
tcpClient, &TcpClient::onClientStart);
QObject::connect(threadTcpPort, &QThread::finished,
tcpClient, &TcpClient::deleteLater);
QObject::connect(tcpClient, &TcpClient::quitTcpClient,
threadTcpPort, &QThread::deleteLater);
QObject::connect(this, &TcpPortView::setTcpConnection,
tcpClient, &TcpClient::onSetTcpConnection);
QObject::connect(this, &TcpPortView::setTcpDisconnection,
tcpClient, &TcpClient::onSetTcpDisconnection);
QObject::connect(this, &TcpPortView::sendToServer,
tcpClient, &TcpClient::onSendToServer);
QObject::connect(tcpClient, &TcpClient::confirmTcpConnection,
this, &TcpPortView::onConfirmTcpConnection);
threadTcpPort->start(); // Start TCP Port thread
}
/**
* @brief Class dectructor
*/
TcpPortView::~TcpPortView()
{
if (threadTcpPort->isRunning()) {
threadTcpPort->quit();
threadTcpPort->deleteLater();
}
qDebug() << "By-by from" << this;
delete ui;
}
/**
* @brief setHeader
* @param header
*/
void TcpPortView::setHeader(QString header)
{
ui->tcpHeadLabel->setText(header);
}
/**
* @brief TcpPortView::getClient
* @return
*/
TcpClient* TcpPortView::getClient()
{
return tcpClient;
}
/**
* @brief TcpPortView::onTabChanged
* @param index
*/
void TcpPortView::onTabChanged(int index)
{
currentTab = index;
}
/**
* @brief TcpPortView::onConfirmTcpConnection
* @param isConnected
*/
void TcpPortView::onConfirmTcpConnection(bool isConnected)
{
if (isConnected) {
ui->tcpConnButton->setText("Disconnect");
ui->statusLineEdit->setText("Connected");
}
else {
ui->tcpConnButton->setText("Connect");
ui->statusLineEdit->setText("Disconnected");
}
isTcpConnected = isConnected;
}
/**
* @brief TcpPortView::on_tcpConnButton_clicked
*/
void TcpPortView::on_tcpConnButton_clicked()
{
if (isTcpConnected) {
emit setTcpDisconnection();
}
else {
emit setTcpConnection(ui->tcpHostnameEdit->text(),
ui->tcpPortEdit->text().toUShort());
}
}