QT 网络多线程程序开发,为什么槽函数没有反应
高手帮忙看看,我的socketRecvData函数为什么不响应
在Dialog类中作侦听
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
///创建监听socket
if(!server.listen(QHostAddress::Any,9000)){
QMessageBox::critical(this, tr("Threaded Rpu Server"),
tr("Unable to start the server: %1.")
.arg(server.errorString()));
close();
return;
}
}
在RpuServer.cpp中重写incomingConnection建立新线程
RpuServer::RpuServer(QObject *parent):QTcpServer(parent)
{
}
void RpuServer::incomingConnection(int socketDescriptor)
{
ClientConnThread *thread = new ClientConnThread(socketDescriptor,this);
connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater()));
thread->start();
}
在ClientConnThread.cpp中重写run函数
ClientConnThread::ClientConnThread(int socketDescriptor,QObject *parent)
: QThread(parent),m_socketDescriptor(socketDescriptor)
{
}
void ClientConnThread::run()
{
qDebug("==========ssssssss\n");
QTcpSocket* clientSocket = new QTcpSocket();
if(!clientSocket->setSocketDescriptor(m_socketDescriptor))
{
emit error(clientSocket->error());
return;
}
m_clientSocket = clientSocket;
connect(m_clientSocket,SIGNAL(readyRead()),this,SLOT(socketRecvData()));
}
void ClientConnThread::socketRecvData()
{
do
{
qDebug("为什么进不来");
m_buffer = m_clientSocket->readAll();
char *data = m_buffer.data();
processData(data);
}while(m_clientSocket->bytesAvailable());
}
void ClientConnThread::processData(char* pData)
{
qDebug("为什么进不来");
}