// thread.cpp
#include "thread.h"
Thread::Thread(int socketDescriptor, QObject *parent)
: QThread(parent)
{
m_socketDescriptor = socketDescriptor;
}
Thread::~Thread()
{
}
void Thread::run()
{
m_tcpSocket = new QTcpSocket;
if (!m_tcpSocket->setSocketDescriptor(m_socketDescriptor))
{
emit error(m_tcpSocket->error());
return;
}
connect(m_tcpSocket,SIGNAL(readyRead()),this, SLOT(readData_slot()), Qt::DirectConnection); // Qt::DirectConnection线程内传递消
connect(m_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(tcpSocket_error_slot()));
connect(m_tcpSocket,SIGNAL(disconnected()),this,SLOT(quit()));//socket断开连接,线程退出
qDebug() << "run" << m_tcpSocket->peerAddress().toString();