1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| if(ui->LinkBotton->property("Mode")=="Server"){ m_tcpServer=new QTcpServer(this); if(!m_tcpServer->listen(QHostAddress::AnyIPv4,6666)){ qDebug()<<m_tcpServer->errorString(); close(); } connect(m_tcpServer,&QTcpServer::newConnection,this,&MainWindow::onNewConnect); connect(m_tcpServer,&QTcpServer::newConnection,this,&MainWindow::onSendBackMsg); } else if(ui->LinkBotton->property("Mode")=="Client"){ m_tcpSocket=new QTcpSocket(this); connect(m_tcpSocket,&QTcpSocket::readyRead, this,&MainWindow::onReadMessage); connect(m_tcpSocket,SIGNAL(QAbstractSocket::SocketError), this,SLOT(onDisplayError(QAbstractSocket::SocketError))); m_tcpSocket->abort(); m_tcpSocket->connectToHost(ui->Host->text(), ui->Port->text().toInt()); }
|