Clarify QByteArray::size() documentation.

QTBUG-25438

Change-Id: I8cf9bfb295195548b6f7d4410682e4d675181a65
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
This commit is contained in:
Mitch Curtis 2012-05-24 10:42:44 +02:00 committed by Qt by Nokia
parent 9a17206b5c
commit ccd56e9844
2 changed files with 25 additions and 1 deletions

View File

@ -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]
}

View File

@ -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.