i wanna save state of QCheckBok in QSetting, i can cast its value to int but maybe exists more simple and proper method to do it?
here is my code:
QSetting setting;
Qt::CheckState checkState;
//...
checkState = (Qt::CheckState)setting.value("checkState", Qt::Unchecked).toUInt();
//...
setting.setValue("checkState", (uint)checkState);
setting.sync();
Firstly, try to avoid C-style casts. For example, replace the following line:
with this:
The line where you cast
checkState
to auint
should also be changed.Secondly, QSettings relies on QVariant for setting and retrieving values. QVariant can usually be expanded to support additional types using the Q_DECLARE_METATYPE macro. Here's the documentation:
http://doc.trolltech.com/4.6/qmetatype.html#Q_DECLARE_METATYPE
However, this mechanism does not appear to work properly with enumerations (when you call the
value()
member function on QVariant). So what you have right now (minus the C-style casting) is fine.