[Interest] C++11 enum class and QSettings

Michael Sué sue at sf.mpg.de
Mon Dec 5 08:48:59 CET 2016


Hi,

with a enum class you'll need to give the type explicitly, as there is no auto-conversion to int:

     settings.setValue("report.stacking", QVariant::fromValue<ReportStacking>(report_stacking));

The same with QVariant::value: var.value<ReportStacking>();

- Michael.

-----Original Message-----
From: Interest [mailto:interest-bounces+sue=sf.mpg.de at qt-project.org] On Behalf Of Bob Hood
Sent: Monday, December 5, 2016 4:16 AM
To: interest at qt-project.org
Subject: [Interest] C++11 enum class and QSettings

I'm trying to save a C++11 enum class value in a QSettings.  In a header I have:

     #include <QMetaType>

     enum class ReportStacking
     {
         Stacked,
         Intermixed
     };
     Q_DECLARE_METATYPE(ReportStacking)




More information about the Interest mailing list