diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-07-31 11:51:23 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2020-08-04 19:52:22 +0200 |
commit | 8003ae79bfd72736b809805afbb7984c3431031e (patch) | |
tree | ac46396976bfb3c96341ed441b06f3c1b9ab6f85 /src/corelib/doc/snippets/code | |
parent | 883f2dd81f8d85d52130aece540cdf9efa3d0069 (diff) |
Document the changed semantics when passing arrays to QByteArray methods
After adding QByteArrayView overloads of QByteArray methods that used
to take char*, the way of determining the length of passed fixed-sized
array data has changed, due to the QByteArraiyView's optimization to deduce
the length at compile time for arrays. Document the behavior and add a
changelog item.
[ChangeLog][QtCore][QByteArray] When passing fixed size C arrays to
QByteArray methods, the length of the data on which the method will operate
is determined by array size, and not by scanning for the first '\0'
terminator, as it was in Qt 5.
Task-number: QTBUG-85815
Change-Id: I11cba17d428791e06c9bd4c7a727b7bd6b6aec3c
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets/code')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp index 74f14f2a4b..196c992c8e 100644 --- a/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp @@ -504,6 +504,16 @@ qDebug(ba.constData()); QByteArray ba = QByteArrayLiteral("byte array contents"); //! [53] +//! [54] +QByteArray ba("abc"); +const char big[10] = "abc"; +ba.compare(big); // returns -1, big is longer than ba + +// In contrast: +const char arr[] = "abc"; +ba.compare(arr); // returns 0, both have the same size and data + +const char *str = "abc"; +ba.compare(str); // returns 0, the size is determined by scanning for '\0' +//! [54] } - - |