diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index a29be8969a..f916582f41 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -1995,6 +1995,14 @@ QTextStream &QTextStream::operator>>(char &c) return *this; } +/*! + \fn QTextStream &QTextStream::operator>>(char16_t &c) + \overload + \since 6.4 + + Reads a character from the stream and stores it in \a c. +*/ + /*! Reads an integer from the stream and stores it in \a i, then returns a reference to the QTextStream. The number is cast to diff --git a/src/corelib/serialization/qtextstream.h b/src/corelib/serialization/qtextstream.h index 05631c0883..054a5d0972 100644 --- a/src/corelib/serialization/qtextstream.h +++ b/src/corelib/serialization/qtextstream.h @@ -153,6 +153,8 @@ public: QTextStream &operator>>(QChar &ch); QTextStream &operator>>(char &ch); + QTextStream &operator>>(char16_t &ch) + { QChar c; *this >> c; ch = c.unicode(); return *this; } QTextStream &operator>>(signed short &i); QTextStream &operator>>(unsigned short &i); QTextStream &operator>>(signed int &i); diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 5a7be18823..7f674cda42 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -1929,10 +1929,19 @@ void tst_QTextStream::char16_t_operators_FromDevice_data() // ------------------------------------------------------------------------------ void tst_QTextStream::char16_t_operators_FromDevice() { + QFETCH(QByteArray, input); QFETCH(const QChar, qchar_output); QFETCH(const QByteArray, write_output); const char16_t char16_t_output = qchar_output.unicode(); + QBuffer buf(&input); + buf.open(QBuffer::ReadOnly); + QTextStream stream(&buf); + stream.setEncoding(QStringConverter::Latin1); + char16_t tmp; + stream >> tmp; + QCOMPARE(tmp, qchar_output); + QBuffer writeBuf; writeBuf.open(QBuffer::WriteOnly);