我刚刚自己实现了 QTcpServer 并重载了该incomingConnection
函数。
void Server::incomingConnection(int handle) //Server inherits from QTcpServer
{
qDebug()<<"Server::incomingConnection"<<handle;
Thread *thread = new Thread(handle,this);
connect(thread,SIGNAL(finished()),this,SLOT(deleteLater()));
thread->start();
}
在线程中,我做了以下事情:
void Thread::run()
{
qDebug() << m_socketDescriptor << "Starting Thread";
m_socket = new QTcpSocket();
if(!m_socket->setSocketDescriptor(m_socketDescriptor))
return;
connect(m_socket,SIGNAL(readyRead()),this,SLOT(readyRead()));
connect(m_socket,SIGNAL(disconnected()),this,SLOT(disconnected()));
qDebug() << m_socketDescriptor << "Client connected";
exec();
}
现在我有一个多线程服务器。
但是我怎样才能访问连接的客户端并通过它们发送数据。一个gui?
先感谢您!
问候