PDA

View Full Version : QTcpSocket not recognizing disconnect



jimroos
5th September 2007, 21:41
I've setup two QTcpServer threads (one for input and one for output) with a circular buffer between them. I issue the exec() command within both threads after starting the listeners. When I connect using a telnet session to both threads I'm capturing the newConnection() signals and successfully opening the input and output sockets.

I setup and capture the readyRead(), disconnected(), stateChanged(), and error() signals with no problem as long as I have not received/sent any data. With out reading/writing any data I can close both telnet sessions and re-open the sessions. However, if I type any data (even 1 character) in the input terminal and it is transmitted to the output terminal I no longer catch any of the signals on the output (write) thread only - the input thread still works with no problem.

The output thread looks in the circular buffer for new data to send after it has received a signal (passed through both threads parent). The write signal is emitted by the input thread after it has deposited the data in the circular buffer.

I'm running on windows with VS2005, QT 4.3.1. I have attempted to disable the QSocketNotifier as discussed in the QSocketNotifier text in QAssistant but I had no luck. I create a QSocketNotifier within my write slot method and disabled / enabled the notifier on either side of writing the data to the socket (i also included a socket->flush() call).

Any ideas, suggestions, example code would be appreciated.

Thanks in advance

Jim

wysota
6th September 2007, 02:11
We'd have to see the code you wrote to be able to suggest a solution.

jimroos
6th September 2007, 15:36
I've tracked the problem to the input threads signal being sent to the output threads write slot. The output write slot is owned by the input thread in this case and I get the following message when I write to the socket:

QObject: Cannot create children for a parent that is in a different thread.
(Parent is QNativeSocketEngine(00B4EC18), parent's thread is TCPServerThread(00B441F8), current thread is QThread(009F68A8)

Does any body have any idea on how I can signal from the input thread to the output thread that data is waiting in the circular buffer but have the output thread invoke the method to actually send the data?

wysota
6th September 2007, 16:31
Please show us the exact code. You seem to be creating objects in wrong places, that's all.