settings - Qt4 QSettings save enumeration value (for example Qt::CheckState) -


i wanna save state of qcheckbok in qsetting, can cast value int maybe exists more simple , proper method it?

here code:

qsetting setting; qt::checkstate checkstate; //... checkstate = (qt::checkstate)setting.value("checkstate", qt::unchecked).touint(); //... setting.setvalue("checkstate", (uint)checkstate); setting.sync(); 

firstly, try avoid c-style casts. example, replace following line:

checkstate = (qt::checkstate)setting.value("checkstate", qt::unchecked).touint(); 

with this:

checkstate = static_cast<qt::checkstate>(setting.value("checkstate", qt::unchecked).touint()); 

the line cast checkstate uint should changed.

secondly, qsettings relies on qvariant setting , retrieving values. qvariant can expanded support additional types using q_declare_metatype macro. here's documentation:

http://doc.trolltech.com/4.6/qmetatype.html#q_declare_metatype

however, mechanism not appear work enumerations (when call value() member function on qvariant). have right (minus c-style casting) fine.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -