diff options
author | Mitch Curtis <mitch.curtis@nokia.com> | 2012-05-24 10:42:44 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-26 02:47:01 +0200 |
commit | ccd56e984497771de7e13bdc286a156296cff58f (patch) | |
tree | cc835afa66a07fb5ba637f02bf615049e8336e47 /src | |
parent | 9a17206b5c9cfaec5f2bff887dfb54bdb572287f (diff) |
Clarify QByteArray::size() documentation.
QTBUG-25438
Change-Id: I8cf9bfb295195548b6f7d4410682e4d675181a65
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp | 19 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 7 |
2 files changed, 25 insertions, 1 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp index a232f490b2..522265b543 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp @@ -416,6 +416,25 @@ strcpy(data, text.data()); delete [] data; //! [47] +//! [48] +QByteArray ba1("ca\0r\0t"); +ba1.size(); // Returns 2. +ba1.constData(); // Returns "ca" with terminating \0. + +QByteArray ba2("ca\0r\0t", 3); +ba2.size(); // Returns 3. +ba2.constData(); // Returns "ca\0" with terminating \0. + +QByteArray ba3("ca\0r\0t", 4); +ba3.size(); // Returns 4. +ba2.constData(); // Returns "ca\0r" with terminating \0. + +const char cart[] = {'c', 'a', '\0', 'r', '\0', 't'}; +QByteArray ba4(QByteArray::fromRawData(cart, 6)); +ba4.size(); // Returns 6. +ba4.constData(); // Returns "ca\0r\0t" without terminating \0. +//! [48] + } diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index c92c269cac..d93c51b7c1 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -681,7 +681,12 @@ static inline char qToLower(char c) A QByteArray can embed '\\0' bytes. The size() function always returns the size of the whole array, including embedded '\\0' - bytes. If you want to obtain the length of the data up to and + bytes, but excluding the terminating '\\0' added by QByteArray. + For example: + + \snippet code/src_corelib_tools_qbytearray.cpp 48 + + If you want to obtain the length of the data up to and excluding the first '\\0' character, call qstrlen() on the byte array. |