关键部分代码这是服务器的代码,对run函数的重新实现;voidTcpThread::run(){tcpSocket=newQTcpSocket;//将Server传来的socketfd与刚创建的tcpSocket关联if(!tcpSocket->setSocketDes...
关键部分代码这是服务器的代码,对run函数的重新实现;void TcpThread::run(){ tcpSocket = new QTcpSocket; //将Server传来的socketfd与刚创建的tcpSocket关联 if(!tcpSocket->setSocketDescriptor(socketfd)) { emit error(tcpSocket->error()); return ; } in.setVersion(QDataStream::Qt_5_1); in.setDevice(tcpSocket); connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(receiveMessage()),Qt::BlockingQueuedConnection); connect(tcpSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this, SLOT(statechanged()),Qt::BlockingQueuedConnection); exec();}登陆函数void TcpThread::UserLogin(){ QString account,passwd; //接收 in>>account>>passwd;//QDataStream in FindUser(account.toUInt(),0,&user); if(user.PASSWD == passwd) { qDebug()<write(outblock); outblock.resize(0); }}当第一次调用的时候就出现警告:QObject: Cannot create children for a parent that is in a different thread.(Parent is QNativeSocketEngine(0x1aa34cc8), parent's thread is TcpThread(0x1aa3a328), current thread is QThread(0x3d4ae8),但是服务器和客户端还是能够收到彼此发过去的数据,但是客户端再一次发送就不能响应了;我想通过一个线程实现客户端的读和写!该怎么改进???
展开