diff options
author | Christoph Schleifenbaum <christoph.schleifenbaum@kdab.com> | 2013-03-09 15:12:20 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-08 06:02:35 +0200 |
commit | f7b313e6d865ac7020c3164c2f6f0232f052eb9b (patch) | |
tree | 9afb8af0bf8283db844df7f72540613d1ef51319 /src/corelib/kernel/qvariant.h | |
parent | 46d80dedb7794c3e494cc818c85e023beb65626e (diff) |
Core: Support for converting user defined QVariant types.
This patchs allows the user to convert defined QMetaType types like
MyType to be converted by using e.g. QVariant::toString(), mapping to
MyType::toString(). Also all the other QVariant::toXYZ() methods are
supported so far.
The patch adds static methods QMetaType::registerConverter supporting:
- implicit convertion
- conversion using member method of source type
- conversion using unary functor
Change-Id: I4f1db83d9c78bcc9df5c42f82f95cce0480cdcc3
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Christoph Schleifenbaum <christoph.schleifenbaum@kdab.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/corelib/kernel/qvariant.h')
-rw-r--r-- | src/corelib/kernel/qvariant.h | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 6f212f5000..0f4102b70a 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -571,11 +571,9 @@ namespace QtPrivate { const int vid = qMetaTypeId<T>(); if (vid == v.userType()) return *reinterpret_cast<const T *>(v.constData()); - if (vid < int(QMetaType::User)) { - T t; - if (v.convert(vid, &t)) - return t; - } + T t; + if (v.convert(vid, &t)) + return t; return T(); } #ifndef QT_NO_QOBJECT |