现在需要在主机端(windows)连接多个客户端(linux),子类了一个QObect如下:
class HandlerClients : public QObject {
Q_OBJECT
public:
HandlerClients::HandlerClients(int sockDescriptor)
: QObject()
{
m_sockDescriptor = sockDescriptor;
m_socket = new QTcpSocket(this);
m_socket->setSocketDescriptor(m_sockDescriptor);
connect(m_socket, SIGNAL(readyRead()), this, SLOT(clientReadyRead()));
connect(m_socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
}
}
class HandlerClients::clientReadyRead()
{
/*reveive bytes from clients*/
}
然后每次有新的客户端连接时就会在子类的QServer的incomingConnection中new 一个新的client,并丢到新的线程中,大体代码如下:
void NetServer::incomingConnection(int sockDesp)
{
QThread *thread = new QThread();
HandlerClients *client = new HandlerClients(sockDescriptor);
connect(thread, SIGNAL(finished()), client, SLOT(deleteLater()));
client->moveToThread(thread);
thread->start();
}
现在碰到的问题是,当某个客户端发第一个包时,readyRead可以被正常触发并接收数据;但是发第二个包时,readyRead没有被触发,但是客户端显示数据已经发送出去了。本人对Qt的多线程应用比较菜,请问各位问题可能出在哪?