-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientmainwindow.cpp
More file actions
56 lines (45 loc) · 1.49 KB
/
Copy pathclientmainwindow.cpp
File metadata and controls
56 lines (45 loc) · 1.49 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
// clientmainwindow.cpp
#include <QTableWidget>
#include "clientmainwindow.h"
#include "ui_clientmainwindow.h"
ClientMainWindow::ClientMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ClientMainWindow),
tcpSocket(new QTcpSocket(this))
{
ui->setupUi(this);
connect(tcpSocket, &QTcpSocket::readyRead, this, &ClientMainWindow::readData);
// 在ClientMainWindow的构造函数中添加如下代码
ui->portSpinBox->setMaximum(65535); // 设置端口号的最大值为65535
}
ClientMainWindow::~ClientMainWindow()
{
delete ui;
}
void ClientMainWindow::on_connectButton_clicked()
{
QString serverAddress = ui->serverAddressEdit->text();
qint16 serverPort = ui->portSpinBox->value();
tcpSocket->connectToHost(serverAddress, serverPort);
if (tcpSocket->waitForConnected()) {
qDebug() << "Connected to server!";
} else {
qWarning() << "Unable to connect to server:" << tcpSocket->errorString();
}
}
void ClientMainWindow::on_sendButton_clicked()
{
QString command = ui->commandEdit->text();
tcpSocket->write(command.toUtf8());
}
void ClientMainWindow::on_disconnectButton_clicked()
{
tcpSocket->disconnectFromHost();
}
void ClientMainWindow::readData()
{
QByteArray data = tcpSocket->readAll();
// Process FTP server response
ui->responseTextEdit->append("Received data from server: " + QString(data));
qDebug() << "Received data from server:" << data;
}