PersistentData: Allow for user types with suitable conversions

I ended up not needing that, but this might be useful for others.

Change-Id: Ie3a5a731d9f3f3f456d7cd4164cfa1753e2b54f1
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Daniel Teske
2015-04-23 14:05:54 +02:00
parent d9425c5cc4
commit 2e2d07788e

View File

@@ -90,6 +90,13 @@ static QRect stringToRectangle(const QString &v)
\li list \li list
\endlist \endlist
You can register string-serialize functions for custom types by registering them in the Qt Meta
type system. Example:
\code
QMetaType::registerConverter(&MyCustomType::toString);
QMetaType::registerConverter<QString, MyCustomType>(&myCustomTypeFromString);
\endcode
When entering a value element ( \c <value> / \c <valuelist> , \c <valuemap> ), entry is pushed When entering a value element ( \c <value> / \c <valuelist> , \c <valuemap> ), entry is pushed
accordingly. When leaving the element, the QVariant-value of the entry is taken off the stack accordingly. When leaving the element, the QVariant-value of the entry is taken off the stack
and added to the stack entry below (added to list or inserted into map). The first element and added to the stack entry below (added to list or inserted into map). The first element
@@ -329,7 +336,7 @@ QVariant ParseContext::readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttr
} }
QVariant value; QVariant value;
value.setValue(text); value.setValue(text);
value.convert(QVariant::nameToType(type.toLatin1().data())); value.convert(QMetaType::type(type.toLatin1().data()));
return value; return value;
} }