qt tcp网络编程中要用到几个函数
我搞了几天没明白我到底哪个地方出错误了一直没搞定TCP链接
客户端1 QTcpSocket tcpSocket = new QTcpSocket(this);2 PTcpSocket->connectToHost(QHostAddress::LocalHost,8000);3 connect(PTcpSocket,SIGNAL(connected()),this,SLOT(enable_slot()));4 connect(PTcpSocket,SIGNAL(readyRead()),this,SLOT(readBlock_slot()));void tcpSocket::send_slot(){ QString str = textEdit->toPlainText(); PTcpSocket->write(qPrintable(str));//写}void tcpSocket::readBlock_slot(){ QByteArray byte; byte = PTcpSocket->readAll();//读 textEdit->setPlainText(QString(byte));}服务端1 QTcpServer TcpServer = new QTcpServer(this);2 TcpServer->listen(QHostAddress::LocalHost,8000);3 connect(TcpServer,SIGNAL(newConnection()),this,SLOT(connect_slot()) );void ServerTcp::connect_slot(){ TcpSocket = TcpServer->nextPendingConnection(); connect(TcpSocket,SIGNAL(readyRead()),this,SLOT(read_slot()));}void ServerTcp::read_slot()读取数据{ QByteArray str; TcpSocket->read(str.data(),str.size()); textEdit->setPlainText(str.data()); }