在MainWindow类中声明
QTcpSocket* m_ClientConnection;//服务器连接的客户端
QTcpServer *m_pTcpServer;
void MainWindow::OepnServer()
{
m_ClientConnection = nullptr;
//1. 创建TCP对象
m_pTcpServer = new QTcpServer(this);
//2. 新连接
connect(m_pTcpServer, &QTcpServer::newConnection, this, &MainWindow::AppendClient);
//3. 启动服务端
QHostAddress *IP = new QHostAddress();
IP->setScopeId("127.0.0.1");
if (!m_pTcpServer->listen(*IP,4001))
{
qDebug() << "m_pTcpServer->listen() error";
}
}
void MainWindow::AppendClient()
{
if(m_ClientCo