I am attempting to come up with an algorithm to detect when the "end" of a QIODevice
is reached (meaning no more data will ever be available for reading). Currently, my algorithm looks something like this:
- for sequential devices, wait for the
readChannelFinished()
signal - for regular files, continuously read data until
atEnd()
returnstrue
However, the documentation for atEnd()
contains the following caveat:
For some devices, atEnd() can return true even though there is more data to read. This special case only applies to devices that generate data in direct response to you calling read() (e.g., /dev or /proc files on Unix and OS X, or console input / stdin on all platforms).
This is where my algorithm breaks down. My next idea was to continuously check the value of bytesAvailable()
when reading from a regular file. This yielded some very strange results for /dev/zero
: bytesAvailable()
returned 0
until I invoked read(amount)
, at which point it indicated that there were 16384 - amount
bytes remaining.
Is there any "proper" way to determine if there is still data available to read from a QIODevice
?