Proxy Page | Qt Core (original) (raw)

Macros

Macro Documentation

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.

Flags can be one of the following:

Example of a "primitive" type:

struct Point2D { int x; int y; };

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 = new int[2]; } Point2D(const Point2D &other) { ... } ~Point2D() { delete[] data; }

Point2D &operator=(const Point2D &other) { ... }

int x() const { return data[0]; }
int y() const { return data[1]; }

private: int *data; };

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.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.