PDA

View Full Version : Store an custom enum in QSettings



Lykurg
14th March 2007, 20:59
Hi,

how to store an custom enum with QSettings and restore it?


myClass::myEnum m_enum = settings.value("xxx").value<myClass::myEnum>(); // fails because no Qt-class


Thanks
Lykurg

wysota
14th March 2007, 21:06
There are a few choices... The simplest is to cast your enum to int (and vice versa). If you need something more complicated, you can use Qt object introspection to map from your enum to QString - there even is a thread that discusses this in this forum. Remember, that if you want to use your custom type with QVariant directly, you have to first register it with the meta-type system. It's described in QVariant docs.