PDA

View Full Version : multiple QThreads with QUdpSocket and QTcpServer



radeberger
25th March 2010, 11:25
Hi everybody!

I'm programming an application with QThreads and QUdp/Tcp sockets.

My main thread or GUI creates a secondary thread1 and this one creates two more threads, thread2 and thread3, thread2 contains a QTcpServer and thread3 a QUdpSocket. The sockets are connected to different ports. When a message comes on the QTcpServer port, the readyread signal is emitted but not when a message comes for the QUdpSocket, although I see the messages in wireshark.

The point is: If I only call thread3 from the main thread it receives the readyread signal when a message comes.

In both thread2 and thread3 the signals are connected in the run function like this:



// thread 2
run(){
connect(tcpServer, SIGNAL(newConnection()),SLOT(acceptConnection()), Qt::DirectConnection)
exec()
}
// accept function in thread2
acceptConnection(){
connect(tcpClient, SIGNAL(readyRead()),SLOT(startRead()), Qt::DirectConnection);
}

// thread 3
run{
connect(traceMessage, SIGNAL(readyRead()), SLOT(readPendingDatagrams()), Qt::DirectConnection);
exec()
}



Is there a problem for thread1 to emit two signals readyread for thread2 and thread3?

has anyone any ideas?

Thank you very much!