I am implementing an XML-based format to save and restore QSettings - basically using QSettings::registerFormat() with my own ReadFunc() and WriteFunc() methods that use QXmlStreamReader and QXmlStreamWriter respectively.

I have writing working just fine. I also have *most* of the reading part working as well. When I write a QSettings value out, I store the string representation of the value along with the string representation of the value's metatype. For example, the QColor "red" gets written to XML as the element:

<Color value="#ff0000" type="QColor"/>

When I read it back in, I retrieve the type name and use QMetaType::nameToType() to get an integer QMetaType type id value. I can then use QMetaType::create() with this type value.

So, what I get is a void * pointer to some memory that actually contains a QColor instance. I don't actually know it is a QColor except indirectly through the type id.

I could conceivably implement a gigantic switch() statement that checked the type id against every QMetaType::Type constant, and cast the result of QMetaType::create() appropriately, but this seems like a stupid way to do it. I'd have to include the header files for almost every fundamental type in Qt.

It looks like the QMetaType::load() method might be a generic way that would work for this. If I used QMetaType::save() to write my values to strings that get saved to the XML file and QMetaType::load() to retrieve them from the strings that are read in, is that the way to do it?