Results 1 to 3 of 3

Thread: help with readyRead() signal "mechanics"

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default help with readyRead() signal "mechanics"

    Hi,

    In the new "C++ programming with Qt4" book, in page 331, there is an example of a server-client application, and in the method that does the actual data reading from the server there is the following code:
    Qt Code:
    1. //'in' is a QDataStream bound to the socket
    2. if(batesAvailable() < sizeof(quint16) ) //the first fielld in the block should be sizeof quint16
    3. return;
    4. in>> nextBlockSize; //read the first field which holds the next block size;
    5. if(bytesAvailable() < nextBlockSize)
    6. return;
    7.  
    8. //code for reading the whole block.
    To copy to clipboard, switch view to plain text mode 
    What I understand from this code is, that the readyRead() signal is emmited each time a new byte is added to the send buffer on the server side, other wise the code above would not work (and I am assuming it does).
    The text in the book doesn't relate at all to this point, so I was wondering if some of you with some experience with socket programming with Qt4 could confirm my assumption.
    The reason I have trouble accepting this, is that it means that QTcpSocket class will emit as many signals as bytes that the server will send, and seems to me that its a lot of overhead....
    On the other hand it could be I am missing here something, and hope you can point me to what it might be

    Thanks.
    Last edited by high_flyer; 13th August 2006 at 16:00.

  2. #2
    Join Date
    Aug 2006
    Location
    Switzerland
    Posts
    52
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: help with readyRead() signal "mechanics"

    Hello!

    I admit that I'm not a qt expert but I guess that signal is emitted every time a TCP segment is received. And TCP stack at client side decides how many bytes will be in that segment. So if client wants to send ie. 100 bytes of data, that it can be received at server side all in one segment (and one signal will be emitted) or in 2 segments (and two signals will be emitted) or in 3 segments, etc..

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: help with readyRead() signal "mechanics"

    Thats sounds logical, thanks.
    With your comment, the docs make more sense to me now:
    void QIODevice::readyRead () [signal]

    This signal is emitted once every time new data is available for reading from the device. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device.

    readyRead() is not emitted recursively; if you reenter the event loop or call waitForReadyRead() inside a slot connected to the readyRead() signal, the signal will not be reemitted (although waitForReadyRead() may still return true).

    See also bytesWritten().

Similar Threads

  1. Replies: 2
    Last Post: 17th May 2006, 21:01
  2. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 15:17
  3. send signal from QCombobox
    By raphaelf in forum Qt Programming
    Replies: 22
    Last Post: 28th February 2006, 14:18
  4. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52
  5. No such signal...
    By chaimar in forum Qt Programming
    Replies: 12
    Last Post: 24th January 2006, 22:33

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.