Results 1 to 4 of 4

Thread: QTcpSocket waitForReadyRead() not re-emitting signal

  1. #1
    Join Date
    Mar 2011
    Posts
    82
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTcpSocket waitForReadyRead() not re-emitting signal

    Hi. I have a QTcpScocket whose readyReady() signal is connected to a slot that handles it.

    *Outside* of the scope of said slot I have another method that writes to the socket and then I call waitForReadyRead() in this manner

    Qt Code:
    1. m_tcpSocket->write((char *)buffer, bufferSize);
    2. m_tcpSocket->waitForReadyRead(5000);
    To copy to clipboard, switch view to plain text mode 

    because I need that particular code block to be blocking until I get a response.

    Problem is that if I use the waitForReadyRead method, it never re-emits the signal so that the slot can handle the incoming data. If I remove the waitForReadyRead, it works just fine, but it is non-blocking, so the tcpSocket just writes a second message without waiting for the reply to the first one.

    Reading the documentation, it says that
    If called from within a slot connected to the readyRead() signal, readyRead() will not be reemitted., which is not my case. I am NOT calling waitForReadyRead from within a slot. And I understand from that sentence that, if not called from within a slot, it will re-emit the signal.

    I do not wish to call the slot as a method right after the waitForReadyRead(), it just doesn't seem appropiate.

    Maybe I actually need to re-implent the waitForReadyRead() to re-emit the signal?

    Any ideas on this issue?

    Additional info: waitForReadyRead() is returning true. I don't know if this is useful or not, but better safe than sorry.

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket waitForReadyRead() not re-emitting signal

    Hi,

    Why are you mixing blocking and non-blocking code? If you want to use a blocking code use only "waitForReadyRead" method.
    Òscar Llarch i Galán

  3. #3
    Join Date
    Mar 2011
    Posts
    82
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket waitForReadyRead() not re-emitting signal

    Because this part of my application needs to be blocking. But not all of it.

    Other than that, how would I be able to know when there is incoming data to the socket if I did not have the readyRead() signal connected to my slot?

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket waitForReadyRead() not re-emitting signal

    Hi,

    I recommend you to use the non-blocking method. You can wait to get the response on the slot connected to the "readyRead" signal. If you know how many bytes you are waiting or maybe a special end of message character.
    Òscar Llarch i Galán

Similar Threads

  1. emitting a signal with no button?
    By kja in forum Newbie
    Replies: 3
    Last Post: 29th November 2010, 21:33
  2. Problem emitting a signal
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2009, 00:56
  3. Emitting signal from DLL to EXE
    By Miihkali in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2009, 08:32
  4. Emitting signal causes CRASH
    By navi1084 in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2009, 16:17
  5. cost of emitting signal
    By quickNitin in forum Newbie
    Replies: 1
    Last Post: 29th November 2006, 08:53

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.