Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtypeinfo.qdoc
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \macro Q_DECLARE_TYPEINFO(Type, Flags)
6 \relates <QTypeInfo>
7
8 You can use this macro to specify information about a custom type
9 \a Type. With accurate type information, Qt's \l{Container Classes}
10 {generic containers} can choose appropriate storage methods and
11 algorithms.
12
13 \a Flags can be one of the following:
14
15 \list
16 \li \c Q_PRIMITIVE_TYPE specifies that \a Type requires no
17 operation to be performed in order to be properly destroyed,
18 and that it is possible to use memcpy() in order to create a
19 valid independent copy of an object.
20 \li \c Q_RELOCATABLE_TYPE specifies that \a Type has a constructor
21 and/or a destructor, but it can still be \e{relocated} in memory
22 by using \c memcpy().
23 \li \c Q_MOVABLE_TYPE is the same as \c Q_RELOCATABLE_TYPE. Prefer to use
24 \c Q_RELOCATABLE_TYPE in new code. Note: despite the name, this
25 has nothing to do with move constructors or C++ move semantics.
26 \li \c Q_COMPLEX_TYPE (the default) specifies that \a Type has
27 constructors and/or a destructor and that it may not be moved
28 in memory.
29 \endlist
30
31 Example of a "primitive" type:
32
33 \snippet code/src_corelib_global_qglobal.cpp 38
34
35 An example of a non-POD "primitive" type is QUuid: Even though
36 QUuid has constructors (and therefore isn't POD), every bit
37 pattern still represents a valid object, and memcpy() can be used
38 to create a valid independent copy of a QUuid object.
39
40 Example of a relocatable type:
41
42 \snippet code/src_corelib_global_qglobal.cpp 39
43
44 Qt will try to detect the class of a type using standard C++ type traits;
45 use this macro to tune the behavior.
46 For instance many types would be candidates for Q_RELOCATABLE_TYPE despite
47 not being trivially-copyable.
48*/