radeberger
5th May 2010, 07:42
Hi guys,
I have one QTcpServer that must deal with several QTcpSocket clients. For this purpose I wanted to use 2 QSignalMapper for the newConnection() and readyRead signals as follows:
// this runs in a separate thread
void myServerThread::run(){
for(count=0;count<numConn;count++){
signalMapperAcceptConnection->setMapping( tcpServer[count], count);
signalMapperReadData->setMapping( tcpClient[count], count);
connect(tcpServer[count], SIGNAL(newConnection()), signalMapperAcceptConnection, SLOT(map()));
}
connect( signalMapperAcceptConnection, SIGNAL(mapped(int)), this, SLOT(acceptConnection(int)),
Qt::DirectConnection);
exec();
}
void myServerThread::acceptConnection(int objectID){
static unsigned short signalCounter = 0;
tcpClient[objectID] = tcpServer[objectID]->nextPendingConnection();
connect( tcpClient[objectID], SIGNAL(readyRead()), signalMapperReadData, SLOT(map()));
signalCounter++;
if(signalCounter == numConn)
connect( signalMapperReadData, SIGNAL(mapped(int)), this, SLOT(startRead(int)), Qt::DirectConnection);
}
The first signal mapper works fine, the signal newConnection() is mapped into the acceptConnection slot with the correct ID but the problem is with the second signalmapper. The signal readyRead() doesn't come, althought a client is sending data.
Do you know what I'm doing wrong?
Thanks in advance!
I have one QTcpServer that must deal with several QTcpSocket clients. For this purpose I wanted to use 2 QSignalMapper for the newConnection() and readyRead signals as follows:
// this runs in a separate thread
void myServerThread::run(){
for(count=0;count<numConn;count++){
signalMapperAcceptConnection->setMapping( tcpServer[count], count);
signalMapperReadData->setMapping( tcpClient[count], count);
connect(tcpServer[count], SIGNAL(newConnection()), signalMapperAcceptConnection, SLOT(map()));
}
connect( signalMapperAcceptConnection, SIGNAL(mapped(int)), this, SLOT(acceptConnection(int)),
Qt::DirectConnection);
exec();
}
void myServerThread::acceptConnection(int objectID){
static unsigned short signalCounter = 0;
tcpClient[objectID] = tcpServer[objectID]->nextPendingConnection();
connect( tcpClient[objectID], SIGNAL(readyRead()), signalMapperReadData, SLOT(map()));
signalCounter++;
if(signalCounter == numConn)
connect( signalMapperReadData, SIGNAL(mapped(int)), this, SLOT(startRead(int)), Qt::DirectConnection);
}
The first signal mapper works fine, the signal newConnection() is mapped into the acceptConnection slot with the correct ID but the problem is with the second signalmapper. The signal readyRead() doesn't come, althought a client is sending data.
Do you know what I'm doing wrong?
Thanks in advance!