From 03272e601ce0b03c36717dac0a60c2fdd8987bee Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Sat, 3 Jul 2021 16:03:54 +0300 Subject: Clarify readLine() behavior on sequential devices QIODevice::readLine() can also return partial lines, which was not properly documented. Add an autotest for QLocalSocket to illustrate and test this behavior. Pick-to: 6.2 Change-Id: Ia2c1c438cc68d2672d34881e11fdf7837232f3b4 Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qiodevice.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 3e3ee6e406..66274e8115 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1320,12 +1320,17 @@ QByteArray QIODevice::readAll() newline will not be inserted into the buffer. On windows newline characters are replaced with '\\n'. + Note that on sequential devices, data may not be immediately available, + which may result in a partial line being returned. By calling the + canReadLine() function before reading, you can check whether a complete + line (including the newline character) can be read. + This function calls readLineData(), which is implemented using repeated calls to getChar(). You can provide a more efficient implementation by reimplementing readLineData() in your own subclass. - \sa getChar(), read(), write() + \sa getChar(), read(), canReadLine(), write() */ qint64 QIODevice::readLine(char *data, qint64 maxSize) { -- cgit v1.2.3