How do I determine that I am at the "end" of a QIODevice?
I'm trying to find an algorithm to detect when the "end" is reached QIODevice
(which means no data will ever be readable). Currently my algorithm looks something like this:
- for serial devices, wait for a signal
readChannelFinished()
- for regular files, read data continuously until
atEnd()
it returnstrue
However, the documentation for atEnd()
contains the following caveat:
For some devices, atEnd () may return true even if there is more data to read. This special case only applies to devices that generate data in direct response to read () calls (for example, / 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 constantly check the value bytesAvailable()
when reading from a regular file. This gave some very strange results for /dev/zero
: bytesAvailable()
returned 0
until I called read(amount)
, after which it indicated there were 16384 - amount
bytes left .
Is there any "correct" way to determine if more data is still readable from QIODevice
?
source to share
No one has answered this question yet
Check out similar questions: