An error value of -1 is returned for several functions in the QIODevice . Qt often uses the C style to handle errors using return values ββto avoid the need for a compiler or platform that supports the use of C ++ exceptions. It is important to check these error codes.
From the manual :
QIODevice::write and QIODevice::writeData
Returns the number of bytes actually written, or -1 if an error occurred.
QIODevice::read(char*,qint64)
If an error occurs, this function returns -1.
QIODevice::readData(char*,qint64)
... and returns the number of bytes read, or -1 if an error occurred.
QIODevice::peek(char*,qint64)
If an error occurs, this function returns -1.
source share