feat: 添加指令回显功能
This commit is contained in:
parent
3534d04fc3
commit
aae38396f4
|
@ -4,6 +4,9 @@
|
||||||
"ostream": "cpp",
|
"ostream": "cpp",
|
||||||
"iostream": "cpp",
|
"iostream": "cpp",
|
||||||
"qmainwindow": "cpp",
|
"qmainwindow": "cpp",
|
||||||
"new": "cpp"
|
"new": "cpp",
|
||||||
|
"qtcpsocket": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"string": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -28,6 +28,7 @@ void MainWindow::start_connet()
|
||||||
tcp_socket = new QTcpSocket(this);
|
tcp_socket = new QTcpSocket(this);
|
||||||
tcp_socket->connectToHost(ui->le_server_ip->text(), ui->le_port->text().toInt());
|
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::connected, this, &MainWindow::connected);
|
||||||
|
connect(tcp_socket, &QTcpSocket::readyRead, this, &MainWindow::receive_cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MainWindow::connected(){
|
void MainWindow::connected(){
|
||||||
|
@ -51,7 +52,15 @@ void MainWindow::send_cmd(){
|
||||||
|
|
||||||
if (tcp_socket != nullptr)
|
if (tcp_socket != nullptr)
|
||||||
{
|
{
|
||||||
|
ui->tb_msgbox->append("[S]" + ui->le_cmd->text());
|
||||||
QByteArray data = ui->le_cmd->text().toUtf8();
|
QByteArray data = ui->le_cmd->text().toUtf8();
|
||||||
tcp_socket->write(data);
|
tcp_socket->write(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void MainWindow::receive_cmd()
|
||||||
|
{
|
||||||
|
QByteArray data = tcp_socket->readAll();
|
||||||
|
QString str = data.data();
|
||||||
|
str="[R]" + str;
|
||||||
|
ui->tb_msgbox->append(str);
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ public slots:
|
||||||
void stop_connet();
|
void stop_connet();
|
||||||
void connected();
|
void connected();
|
||||||
void send_cmd();
|
void send_cmd();
|
||||||
|
void receive_cmd();
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QTcpSocket *tcp_socket;
|
QTcpSocket *tcp_socket;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTextBrowser" name="textBrowser"/>
|
<widget class="QTextBrowser" name="tb_msgbox"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_3">
|
<widget class="QGroupBox" name="groupBox_3">
|
||||||
|
|
Loading…
Reference in New Issue