From aae38396f4bc92d282fd120afa1d76719a9c694a Mon Sep 17 00:00:00 2001 From: chenyf <1343619937@qq.com> Date: Mon, 9 Sep 2024 09:52:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E5=9B=9E=E6=98=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 ++++- mainwindow.cpp | 11 ++++++++++- mainwindow.h | 1 + mainwindow.ui | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a64b333..48d5855 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,9 @@ "ostream": "cpp", "iostream": "cpp", "qmainwindow": "cpp", - "new": "cpp" + "new": "cpp", + "qtcpsocket": "cpp", + "*.tcc": "cpp", + "string": "cpp" } } \ No newline at end of file diff --git a/mainwindow.cpp b/mainwindow.cpp index 1552b7d..6cbc396 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -28,6 +28,7 @@ void MainWindow::start_connet() tcp_socket = new QTcpSocket(this); tcp_socket->connectToHost(ui->le_server_ip->text(), ui->le_port->text().toInt()); connect(tcp_socket, &QTcpSocket::connected, this, &MainWindow::connected); + connect(tcp_socket, &QTcpSocket::readyRead, this, &MainWindow::receive_cmd); } } void MainWindow::connected(){ @@ -51,7 +52,15 @@ void MainWindow::send_cmd(){ if (tcp_socket != nullptr) { + ui->tb_msgbox->append("[S]" + ui->le_cmd->text()); QByteArray data = ui->le_cmd->text().toUtf8(); tcp_socket->write(data); } -} \ No newline at end of file +} +void MainWindow::receive_cmd() +{ + QByteArray data = tcp_socket->readAll(); + QString str = data.data(); + str="[R]" + str; + ui->tb_msgbox->append(str); +} \ No newline at end of file diff --git a/mainwindow.h b/mainwindow.h index 6962743..cb50029 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -22,6 +22,7 @@ public slots: void stop_connet(); void connected(); void send_cmd(); + void receive_cmd(); private: Ui::MainWindow *ui; QTcpSocket *tcp_socket; diff --git a/mainwindow.ui b/mainwindow.ui index 24988f1..e10fe91 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -28,7 +28,7 @@ - +