Solved Save and read enum by QSettings
-
*.h { private: enum { TEXT_CLOCK, DIGITAL_CLOCK, ANALOG_CLOCK } clock_type; } *.cpp { QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); clock_type = settings.value("ClockType"); if (clock_type == NULL) clock_type = TEXT_CLOCK; QAction *action_text = new QAction("Text", this); connect(action_text, &QAction::triggered, [=](){ clock_type = TEXT_CLOCK; settings.setValue("ClockType", clock_type); }); addAction(action_text); }
-
Is it so hard to write down what your problem is instead simply posting a code snippet?
-
@sonichy you did not specify a type for your enum, so it's an normal int (int32_t) simply cast it to and from the enum type.
-
This post is deleted! -
@sonichy said in Save and read enum by QSettings:
clock_type = settings.value("ClockType"); if (clock_type == NULL)
If you look at the docs for QSettings::value() you will see that it returns a QVariant.
So such a check doesnt make much sense. -
enum ClockType { TEXT_CLOCK, DIGITAL_CLOCK, ANALOG_CLOCK }; ClockType clockType; settings.setValue("ClockType", clockType); //save clockType = static_cast<ClockType>(settings.value("ClockType").toInt()); //read