Clarify QByteArray::size() documentation.
authorMitch Curtis <mitch.curtis@nokia.com>
Thu, 24 May 2012 08:42:44 +0000 (10:42 +0200)
committerQt by Nokia <qt-info@nokia.com>
Sat, 26 May 2012 00:47:01 +0000 (02:47 +0200)
QTBUG-25438

Change-Id: I8cf9bfb295195548b6f7d4410682e4d675181a65
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp
src/corelib/tools/qbytearray.cpp

index a232f49..522265b 100644 (file)
@@ -416,6 +416,25 @@ strcpy(data, text.data());
 delete [] data;
 //! [47]
 
 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]
+
 }
 
 
 }
 
 
index c92c269..d93c51b 100644 (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'
 
     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.
 
     excluding the first '\\0' character, call qstrlen() on the byte
     array.