forked from qt-creator/qt-creator
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:
@@ -90,6 +90,13 @@ static QRect stringToRectangle(const QString &v)
|
||||
\li list
|
||||
\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
|
||||
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
|
||||
@@ -329,7 +336,7 @@ QVariant ParseContext::readSimpleValue(QXmlStreamReader &r, const QXmlStreamAttr
|
||||
}
|
||||
QVariant value;
|
||||
value.setValue(text);
|
||||
value.convert(QVariant::nameToType(type.toLatin1().data()));
|
||||
value.convert(QMetaType::type(type.toLatin1().data()));
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user