Re: [Interest] C++11 enum class and QSettings
On 12/5/2016 12:48 AM, Michael Sué wrote: 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(report_stacking)); The same with QVariant::value: var.value(); Thanks, Michael (and everybody else who answered). Your solution worked perfectly with the least amount of changes. ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] C++11 enum class and QSettings
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(report_stacking)); The same with QVariant::value: var.value(); - Michael. -Original Message- From: Interest [mailto:interest-bounces+sue=sf.mpg...@qt-project.org] On Behalf Of Bob Hood Sent: Monday, December 5, 2016 4:16 AM To: interest@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 enum class ReportStacking { Stacked, Intermixed }; Q_DECLARE_METATYPE(ReportStacking) ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] C++11 enum class and QSettings
On domingo, 4 de dezembro de 2016 20:15:42 PST Bob Hood wrote: > QVariant::save: unable to save type 'ReportStacking' (type id: 1027). You need to call qRegisterMetaTypeStreamOperators() for your type so that QVariant knows how to stream into a QDataStream. -- Thiago Macieira - thiago.macieira (AT) intel.com Software Architect - Intel Open Source Technology Center ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
Re: [Interest] C++11 enum class and QSettings
On 5 December 2016 at 16:15, Bob Hoodwrote: > I'm trying to save a C++11 enum class value in a QSettings. In a header I > have: > > #include > > 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 I might be wrong, but i think that Q_DECLARE_METATYPE doesn't cross shared object boundary, if the code serialising the enum isn't in the same shared object that the one that declare it, then you need to call qRegisterMetaType() from your main object. Chris > > 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 ___ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
[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 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