summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-03-30 14:09:15 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-09 12:54:49 +0200
commit39b45781562712f320edb6519aef7b2444699848 (patch)
tree1d7fe7d4cec08106554e4003fa7f48d84555c1fb /src
parent1c20c3f29441a6856c6eb58dda40b86bdaac6a06 (diff)
QTypeInfo: document Q_PRIMITIVE_TYPE existing practice
Despite the documentation requiring Q_PRIMITIVE_TYPEs to be PODs, existing practice in Qt (QFixed, QFlags, QUuid) is to allow constructors on primitive types as long as every bit pattern represents a valid object (ie. memory doesn't have to be initialised to hold an object of the type) and memcpy() can be used to create an independent copy of the object (memcpy()ing QString, e.g., while creating two valid objects, doesn't create independent copies). Change-Id: Ia85d48b89f6cc84e69ea76719eab9a858d247ad6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qglobal.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 8125161897..7d518cbcd8 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -2518,7 +2518,9 @@ int qrand()
\list
\li \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old
- data) type with no constructor or destructor.
+ data) type with no constructor or destructor, or else a type where
+ every bit pattern is a valid object and memcpy() creates a valid
+ independent copy of the object.
\li \c Q_MOVABLE_TYPE specifies that \a Type has a constructor
and/or a destructor but can be moved in memory using \c
memcpy().
@@ -2531,6 +2533,11 @@ int qrand()
\snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 38
+ An example of a non-POD "primitive" type is QUuid: Even though
+ QUuid has constructors (and therefore isn't POD), every bit
+ pattern still represents a valid object, and memcpy() can be used
+ to create a valid independent copy of a QUuid object.
+
Example of a movable type:
\snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 39