Definition
Q_DECLARE_TYPEINFO is used to specialise a template class called QTypeInfo.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Where Q_DECLARE_TYPEINFO is used?
The documention says that:
Q_DECLARE_TYPEINFO( Type, Flags)
You can use this macro to specify information about a custom type Type. With accurate type information, Qt's generic containers can choose appropriate storage methods and algorithms.
Let's find where QTypeInfo is used in Qt's source code:
1 2 3 4 5 6 7 8 9 |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
TYPEINFO flags
We can find following code in qtypeinfo.h:
1 2 3 4 5 6 7 |
|
Q_PRIMITIVE_TYPE
specifies that Type is a POD (plain old 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.Q_MOVABLE_TYPE
specifies that Type has a constructor and/or a destructor but can be moved in memory using memcpy().Q_COMPLEX_TYPE
(the default) specifies that Type has constructors and/or a destructor and that it may not be moved in memory.
For QVector, When an insertion takes place, the elements that come after the point of insertion must be moved one position further. If T is a movable type, this is achieved using memmove(); otherwise, QVector
{% img center /images/blog/2013/q_declare_typeinfo_qvector_insert.png %}
Reference
- http://doc.qt.digia.com/qq/qq19-containers.html
- http://www.drdobbs.com/c-made-easier-plain-old-data/184401508