Why does Qt use qint64 to length and offset data instead of quint64?

QIODevice , and related classes use qint64 for positions and sizes, which is a signed data type. Do negative values ​​need to be expressed? Because otherwise, 8 bytes of this type could be used to express large sizes, right?

+4
source share
1 answer

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.

+6
source

All Articles