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)
And then in the module, using a data member of this type:
ReportStacking report_stacking = ReportStacking::Intermixed;
I've tried both:
QVariant var;
var.setValue(report_stacking);
settings.setValue("report.stacking", var);
and:
settings.setValue("report.stacking", QVariant::fromValue(report_stacking));
and I'm getting a run-time error:
QVariant::save: unable to save type 'ReportStacking' (type id: 1027).
ASSERT failure in QVariant::save: "Invalid type to save", file
kernel\qvariant.cpp, line 2144
Debug Error!
Program: Q:\Qt\5.6.2\64_dll\bin\Qt5Cored.dll
Module: 5.6.2
File: global\qglobal.cpp
Line: 3026
ASSERT failure in QVariant::save: "Invalid type to save", file
kernel\qvariant.cpp, line 2144
Is there a Qt-base way of storing C++11 enum class types, or do I have to do
some manual coding to map a ReportStacking class value to an int for QSettings
to digest?
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest