PDA

View Full Version : QTcpServer in QThread signal problem



radeberger
1st June 2010, 08:19
Hi everybody,

I have a QMainWindow application with 3 instances of a QThread based class (secondThread). This class has one instance of another QThread class (thirdThread) with a QTcpServer object




seconThread::run(){

tcpServer = new thirdThread();
tcpServer->run();

}

thirdThread::run(){

tcpServer = new QTcpServer();
connect(tcpServer, SIGNAL(newConnection()),SLOT(acceptConnection()), Qt::DirectConnection);
if (tcpServer->listen(QHostAddress::Any, port)) {
exec();
}
}

thirdThread::acceptConnection(){
tcpClient = tcpServer->nextPendingConnection();
connect(tcpClient, SIGNAL(readyRead()),SLOT(startRead()), Qt::DirectConnection);

}



If I only work with an instance of secondThread, it works properly, I get the signals accept connection and ready read but If I have more than one instance (I tried with two and three instances) I only get the signals accept and ready read for one of the objects. Is there a problem with the event loop (exec()) if I call it several times?

Thanks in advance!

borisbn
1st June 2010, 10:49
Maybe it happened because your second QTcpServer can't listen the same port at the same ip-address as your first QTcpServer ?
Try to change port number is each thread