Results 1 to 4 of 4

Thread: QTcpSocket not recognizing disconnect

  1. #1
    Join Date
    Mar 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTcpSocket not recognizing disconnect

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket not recognizing disconnect

    We'd have to see the code you wrote to be able to suggest a solution.

  3. #3
    Join Date
    Mar 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket not recognizing disconnect

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket not recognizing disconnect

    Please show us the exact code. You seem to be creating objects in wrong places, that's all.

Similar Threads

  1. Strange QTcpSocket behavior (debugged with Ethereal)
    By mdecandia in forum Qt Programming
    Replies: 23
    Last Post: 28th May 2007, 20:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.