- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

Classes | Namespaces | Defines | Functions

# qmetatype.h File Reference

`#include <QtCore/qglobal.h>`
`#include <QtCore/qatomic.h>`
`#include <QtCore/qdatastream.h>`

Go to the source code of this file.

## Classes
class | QMetaType
struct | QMetaTypeId< T >
struct | QMetaTypeId2< T >
struct | QMetaTypeIdHelper< T, Defined >
struct | QMetaTypeIdHelper< T, false >
## Namespaces
namespace | QtPrivate
## Defines
#define | Q_DECLARE_METATYPE(TYPE)
#define | Q_DECLARE_BUILTIN_METATYPE(TYPE, NAME)
## Functions
template<typename T >
void | qMetaTypeDeleteHelper (T *t)
template<typename T >
void * | qMetaTypeConstructHelper (const T *t)
template<typename T >
void | qMetaTypeSaveHelper (QDataStream &stream, const T *t)
template<typename T >
void | qMetaTypeLoadHelper (QDataStream &stream, T *t)
template<typename T >
int | qRegisterMetaType (const char *typeName, T *dummy=0)
template<typename T >
void | qRegisterMetaTypeStreamOperators (const char *typeName, T *=0)
template<typename T >
int | qMetaTypeId (T *=0)
template<typename T >
int | qRegisterMetaType (T *dummy=0)
template<typename T >
int | qRegisterMetaTypeStreamOperators ()

## Define Documentation

#define Q_DECLARE_METATYPE | ( |  | TYPE | ) |

Search for all occurrences
Value:

    QT_BEGIN_NAMESPACE                                                  \
        template <>                                                         \
        struct QMetaTypeId< TYPE >                                          \
        {                                                                   \
            enum { Defined = 1 };                                           \
            static int qt_metatype_id()                                     \
                {                                                           \
                    static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
                    if (!metatype_id)                                       \
                        metatype_id = qRegisterMetaType< TYPE >(#TYPE,      \
                                   reinterpret_cast< TYPE *>(quintptr(-1))); \
                    return metatype_id;                                     \
                }                                                           \
        };                                                                  \
        QT_END_NAMESPACE

Definition at line 265 of file qmetatype.h.

#define Q_DECLARE_BUILTIN_METATYPE | ( |  | TYPE,
|  |  | NAME
| ) |  |

Search for all occurrences
Value:

    QT_BEGIN_NAMESPACE \
        template<> struct QMetaTypeId2<TYPE> \
        { \
            enum { Defined = 1, MetaType = QMetaType::NAME }; \
            static inline int qt_metatype_id() { return QMetaType::NAME; } \
        }; \
        QT_END_NAMESPACE

Definition at line 282 of file qmetatype.h.

## Function Documentation

void qMetaTypeDeleteHelper | ( | T * | t | ) |

Search for all occurrences

Definition at line 132 of file qmetatype.h.

    {
        delete t;
    }

void* qMetaTypeConstructHelper | ( | const T * | t | ) |

Search for all occurrences

Definition at line 138 of file qmetatype.h.

    {
        if (!t)
            return new T;
        return new T(*static_cast<const T*>(t));
    }

void qMetaTypeSaveHelper | ( | QDataStream & | stream,
|  | const T * | t
| ) |  |

Search for all occurrences

Definition at line 147 of file qmetatype.h.

    {
        stream << *t;
    }

void qMetaTypeLoadHelper | ( | QDataStream & | stream,
|  | T * | t
| ) |  |

Search for all occurrences

Definition at line 153 of file qmetatype.h.

    {
        stream >> *t;
    }

int qRegisterMetaType | ( | const char * | typeName,
|  | T * | dummy = `0`
| ) |  |

Search for all occurrences

Definition at line 185 of file qmetatype.h.

    {
        const int typedefOf = dummy ? -1 : QtPrivate::QMetaTypeIdHelper<T>::qt_metatype_id();
        if (typedefOf != -1)
            return QMetaType::registerTypedef(typeName, typedefOf);

        typedef void*(*ConstructPtr)(const T*);
        ConstructPtr cptr = qMetaTypeConstructHelper<T>;
        typedef void(*DeletePtr)(T*);
        DeletePtr dptr = qMetaTypeDeleteHelper<T>;

        return QMetaType::registerType(typeName, reinterpret_cast<QMetaType::Destructor>(dptr),
                                       reinterpret_cast<QMetaType::Constructor>(cptr));
    }

void qRegisterMetaTypeStreamOperators | ( | const char * | typeName,
|  | T * | = `0`
| ) |  |

Search for all occurrences

Definition at line 206 of file qmetatype.h.

    {
        typedef void(*SavePtr)(QDataStream &, const T *);
        typedef void(*LoadPtr)(QDataStream &, T *);
        SavePtr sptr = qMetaTypeSaveHelper<T>;
        LoadPtr lptr = qMetaTypeLoadHelper<T>;

        qRegisterMetaType<T>(typeName);
        QMetaType::registerStreamOperators(typeName, reinterpret_cast<QMetaType::SaveOperator>(sptr),
                                           reinterpret_cast<QMetaType::LoadOperator>(lptr));
    }

int qMetaTypeId | ( | T * | = `0` | ) | `[inline]`

Search for all occurrences

Definition at line 224 of file qmetatype.h.

    {
        return QMetaTypeId2<T>::qt_metatype_id();
    }

int qRegisterMetaType | ( | T * | dummy = `0` | ) | `[inline]`

Search for all occurrences

Definition at line 234 of file qmetatype.h.

    {
    #ifdef Q_CC_SUN
        return qMetaTypeId(static_cast<T *>(0));
    #else
        return qMetaTypeId(dummy);
    #endif
    }

int qRegisterMetaTypeStreamOperators | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 249 of file qmetatype.h.

    {
        typedef void(*SavePtr)(QDataStream &, const T *);
        typedef void(*LoadPtr)(QDataStream &, T *);
        SavePtr sptr = qMetaTypeSaveHelper<T>;
        LoadPtr lptr = qMetaTypeLoadHelper<T>;

        register int id = qMetaTypeId<T>();
        QMetaType::registerStreamOperators(id,
                                           reinterpret_cast<QMetaType::SaveOperator>(sptr),
                                           reinterpret_cast<QMetaType::LoadOperator>(lptr));

        return id;
    }