Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Macros for specifying information about custom types.
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.
Flags can be one of the following:
Q_PRIMITIVE_TYPEspecifies thatTyperequires no operation to be performed in order to be properly destroyed, and that it is possible to use memcpy() in order to create a valid independent copy of an object.
Q_RELOCATABLE_TYPEspecifies thatTypehas a constructor and/or a destructor, but it can still be relocated in memory by usingmemcpy().
Q_MOVABLE_TYPEis the same asQ_RELOCATABLE_TYPE. Prefer to useQ_RELOCATABLE_TYPEin new code. Note: despite the name, this has nothing to do with move constructors or C++ move semantics.
Q_COMPLEX_TYPE(the default) specifies thatTypehas constructors and/or a destructor and that it may not be moved in memory.
Example of a “primitive” type:
class Point2D(): x = int() y = int() Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE)
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 relocatable type:
class Point2D(): # public Point2D() { data = int()[2]; } Point2D(Point2D other) { ... } ~Point2D() { delete[] data; } Point2D operator=(Point2D other) { ... } int x() { return data[0]; } int y() { return data[1]; } # private data = int() Q_DECLARE_TYPEINFO(Point2D, Q_RELOCATABLE_TYPE)
Qt will try to detect the class of a type using standard C++ type traits; use this macro to tune the behavior. For instance many types would be candidates for Q_RELOCATABLE_TYPE despite not being trivially-copyable.