From 8fcc4596efc55c498be75ca9067f825e733624df Mon Sep 17 00:00:00 2001 From: Tatiana Borisova Date: Fri, 13 Jun 2025 17:05:37 +0200 Subject: QDataStream: add operator bool() - Add operator bool() that checks whether the associated stream has no error status. This operator makes it possible to use streams and functions that return references to streams as loop conditions: `while (stream >> data)`. - Update existing testcases that use or can use the status of stream operations. [ChangeLog][QtCore][QDataStream] Added implicit conversion to bool, returning `status() == Ok`. Found in API-review (added for symmetry with QTextStream). Pick-to: 6.10 Change-Id: I3eb8251f40eba1a8164e088fa10de670564f428e Reviewed-by: Marc Mutz --- src/corelib/serialization/qdatastream.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/corelib/serialization/qdatastream.cpp') diff --git a/src/corelib/serialization/qdatastream.cpp b/src/corelib/serialization/qdatastream.cpp index 8377cba4ec8..1a1f66a372f 100644 --- a/src/corelib/serialization/qdatastream.cpp +++ b/src/corelib/serialization/qdatastream.cpp @@ -1411,6 +1411,13 @@ QDataStream &operator<<(QDataStream &out, QChar chr) return out; } +/*! + \fn QDataStream::operator bool() const + \since 6.10 + + Returns whether this stream has no errors (status() == \l{OK}). +*/ + /*! Writes the length specifier \a len and the buffer \a s to the stream and returns a reference to the stream. -- cgit v1.2.3