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

- File List
- File Members

Classes | Typedefs | Functions

# qvariant.h File Reference

`#include <QtCore/qatomic.h>`
`#include <QtCore/qbytearray.h>`
`#include <QtCore/qlist.h>`
`#include <QtCore/qmetatype.h>`
`#include <QtCore/qmap.h>`
`#include <QtCore/qhash.h>`
`#include <QtCore/qstring.h>`

Go to the source code of this file.

## Classes
class | QVariant
struct | QVariant::PrivateShared
struct | QVariant::Private
union | QVariant::Private::Data
struct | QVariant::Handler
class | QVariantComparisonHelper
## Typedefs
typedef QList< QVariant > | QVariantList
typedef QMap< QString, QVariant > | QVariantMap
typedef QHash< QString, QVariant > | QVariantHash
## Functions
template<typename T >
QVariant | qVariantFromValue (const T &)
template<typename T >
void | qVariantSetValue (QVariant &, const T &)
template<typename T >
T | qVariantValue (const QVariant &)
template<typename T >
bool | qVariantCanConvert (const QVariant &)
bool | qvariant_cast_helper (const QVariant &v, QVariant::Type tp, void *ptr)
template<>
QVariant | qVariantFromValue (const QVariant &t)
template<>
void | qVariantSetValue< QVariant > (QVariant &v, const QVariant &t)
Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &s, QVariant &p)
Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &s, const QVariant &p)
Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &s, QVariant::Type &p)
Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &s, const QVariant::Type p)
bool | operator== (const QVariant &v1, const QVariantComparisonHelper &v2)
bool | operator!= (const QVariant &v1, const QVariantComparisonHelper &v2)
template<typename T >
T | qvariant_cast (const QVariant &v)
template<>
QVariant | qvariant_cast< QVariant > (const QVariant &v)
| Q_DECLARE_TYPEINFO (QVariant, Q_MOVABLE_TYPE)
Q_CORE_EXPORT QDebug | operator<< (QDebug, const QVariant &)
Q_CORE_EXPORT QDebug | operator<< (QDebug, const QVariant::Type)

## Typedef Documentation

typedef QList<QVariant> QVariantList

Search for all occurrences

Definition at line 447 of file qvariant.h.

typedef QMap<QString, QVariant> QVariantMap

Search for all occurrences

Definition at line 448 of file qvariant.h.

typedef QHash<QString, QVariant> QVariantHash

Search for all occurrences

Definition at line 449 of file qvariant.h.

## Function Documentation

QVariant qVariantFromValue | ( | const T & | t | ) | `[inline]`

Search for all occurrences

Definition at line 455 of file qvariant.h.

    {
        return QVariant(qMetaTypeId<T>(reinterpret_cast<T *>(0)), &t, QTypeInfo<T>::isPointer);
    }

void qVariantSetValue | ( | QVariant & | v,
|  | const T & | t
| ) |  | `[inline]`

Search for all occurrences

Definition at line 464 of file qvariant.h.

    {
        //if possible we reuse the current QVariant private
        const uint type = qMetaTypeId<T>(reinterpret_cast<T *>(0));
        QVariant::Private &d = v.data_ptr();
        if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) {
            d.type = type;
            d.is_null = false;
            T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr);
            if (QTypeInfo<T>::isComplex)
                old->~T();
            new (old) T(t); //call the copy constructor
        } else {
            v = QVariant(type, &t, QTypeInfo<T>::isPointer);
        }
    }

T qVariantValue | ( | const QVariant & | variant | ) | `[inline]`

Search for all occurrences

Definition at line 598 of file qvariant.h.

    { return qvariant_cast<T>(variant); }

bool qVariantCanConvert | ( | const QVariant & | variant | ) | `[inline]`

Search for all occurrences

Definition at line 602 of file qvariant.h.

    {
        return variant.canConvert(static_cast<QVariant::Type>(
                    qMetaTypeId<T>(static_cast<T *>(0))));
    }

bool qvariant_cast_helper | ( | const QVariant & | v,
|  | QVariant::Type | tp,
|  | void * | ptr
| ) |  | `[inline]`

Search for all occurrences

Definition at line 451 of file qvariant.h.

    { return QVariant::handler->convert(&v.d, tp, ptr, 0); }

QVariant qVariantFromValue | ( | const QVariant & | t | ) | `[inline]`

Search for all occurrences

Definition at line 461 of file qvariant.h.

    { return t; }

void qVariantSetValue< QVariant > | ( | QVariant & | v,
|  | const QVariant & | t
| ) |  | `[inline]`

Search for all occurrences

Definition at line 482 of file qvariant.h.

    {
        v = t;
    }

Q_CORE_EXPORT QDataStream& operator>> | ( | QDataStream & | s,
|  | QVariant & | p
| ) |  |

Q_CORE_EXPORT QDataStream& operator<< | ( | QDataStream & | s,
|  | const QVariant & | p
| ) |  |

Q_CORE_EXPORT QDataStream& operator>> | ( | QDataStream & | s,
|  | QVariant::Type & | p
| ) |  |

Q_CORE_EXPORT QDataStream& operator<< | ( | QDataStream & | s,
|  | const QVariant::Type | p
| ) |  |

bool operator== | ( | const QVariant & | v1,
|  | const QVariantComparisonHelper & | v2
| ) |  | `[inline]`

Definition at line 565 of file qvariant.h.

    {
        return v1.cmp(*v2.v);
    }

bool operator!= | ( | const QVariant & | v1,
|  | const QVariantComparisonHelper & | v2
| ) |  | `[inline]`

Definition at line 570 of file qvariant.h.

    {
        return !operator==(v1, v2);
    }

T qvariant_cast | ( | const QVariant & | v | ) | `[inline]`

Search for all occurrences

Definition at line 577 of file qvariant.h.

    {
        const int vid = qMetaTypeId<T>(static_cast<T *>(0));
        if (vid == v.userType())
            return *reinterpret_cast<const T *>(v.constData());
        if (vid < int(QMetaType::User)) {
            T t;
            if (qvariant_cast_helper(v, QVariant::Type(vid), &t))
                return t;
        }
        return T();
    }

QVariant qvariant_cast< QVariant > | ( | const QVariant & | v | ) | `[inline]`

Search for all occurrences

Definition at line 590 of file qvariant.h.

    {
        if (v.userType() == QMetaType::QVariant)
            return *reinterpret_cast<const QVariant *>(v.constData());
        return v;
    }

Q_DECLARE_TYPEINFO | ( | QVariant | ,
|  | Q_MOVABLE_TYPE |
| ) |  |

Search for all occurrences

Q_CORE_EXPORT QDebug operator<< | ( | QDebug | ,
|  | const QVariant & |
| ) |  |

Q_CORE_EXPORT QDebug operator<< | ( | QDebug | ,
|  | const QVariant::Type |
| ) |  |