Results 1 to 2 of 2

Thread: QIODevice read()

  1. #1
    Join Date
    Apr 2007
    Posts
    62
    Thanks
    43
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QIODevice read()

    Hi,

    I want to reimplement the QIODevice's read

    Qt Code:
    1. qint64 QIODevice::read ( char * data, qint64 maxSize )
    To copy to clipboard, switch view to plain text mode 

    as follows:

    - I want the new Read function to block until it has filled nBytes that I want to read.

    Would this function do?

    Qt Code:
    1. bool Read( char* address,
    2. int numBytesToBeRead )
    3. {
    4. do
    5. {
    6. // If waitForReadyRead returns false, there is something wrong
    7. if( mDevice->waitForReadyRead( -1 ) == false )
    8. {
    9. return false;
    10. }
    11. } while( mDevice->bytesAvailable() != numBytesToRead );
    12.  
    13. // Now that there are numBytesToBeRead available, read it all at once
    14. mDevice->read( address, numBytesToBeRead );
    15.  
    16. return true;
    17. }
    To copy to clipboard, switch view to plain text mode 

    A few concerns:

    1) Once there is at least 1 byte to be read in the "pipe," would waitForReadyRead() constantly return? i.e. it wont block anymore since there are bytes to be read even if it's not up to the number of bytes I want to read yet.

    2) Can it be that the "pipe" would eventually be full and that bytesAvailable() will never be equal to numBytesToRead? i.e. if numBytesToRead is 1 GB...maybe if the program doesnt do a read() at all, bytesAvailable will never be equal to 1GB.

    I simply just want an API that's like the POSIX TCP socket where the read() blocks forever waiting for X amount of bytes to come through. Is there something similar in Qt?

  2. #2
    Join Date
    Apr 2007
    Posts
    62
    Thanks
    43
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QIODevice read()

    Oh..or do I have to use this method in conjunction?

    setReadBufferSize( 0 );

    Excerpt from Qt reference manual:
    Exceptionally, a buffer size of 0 means that the read buffer is unlimited and all incoming data is buffered. This is the default.

Similar Threads

  1. How to Read and display BMP image using QT
    By agsrinivasan in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 08:14
  2. Read files PDF
    By henriquez0 in forum Qt Programming
    Replies: 3
    Last Post: 31st December 2006, 01:20
  3. Increasing QProcess read performance
    By mcostalba in forum Qt Programming
    Replies: 9
    Last Post: 4th December 2006, 21:12
  4. How to read line from file
    By Krishnacins in forum Newbie
    Replies: 10
    Last Post: 2nd June 2006, 00:14
  5. Replies: 13
    Last Post: 1st June 2006, 15:01

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.