Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

qRegisterMetaTypeStreamOperators issue

$
0
0
Hello, I’m trying to store a structure with QSettings. I followed the following instructions (Saving custom structures and classes to QSettings [developer.nokia.com]). My structure is looking like this: struct ReferenceT {  uint  nId;  uint  nIndex;  QColor  colorRef;  QString  sLabel;  bool  bVFlip;  ReferenceT(): nId(0), nIndex(0), colorRef(QColor(255, 0, 0)), sLabel(QObject::tr("Reference")), bVFlip(false){}; };   Q_DECLARE_METATYPE(ReferenceT); Then in the C++ file for the class I’m developing I declared the stream operators like this: QDataStream &operator<<(QDataStream &out, const ReferenceT &obj) {  out << obj.nId << obj.nIndex << obj.colorRef << obj.sLabel << obj.bVFlip;  return out; }   QDataStream &operator>>(QDataStream &in, ReferenceT &obj) {  in >> obj.nId >> obj.nIndex >> obj.colorRef >> obj.sLabel >> obj.bVFlip;  return in; } I declared the type and stream operator like this: qRegisterMetaType<ReferenceT>("ReferenceT"); qRegisterMetaTypeStreamOperators<ReferenceT>("ReferenceT"); My save settings function looks like this: QSetting settings; ReferenceT reference; // ... settings.setValue(sRef, qVariantFromValue(reference)); The save function appear to save the actual data. When I look at the binary signatures, there are different for references having different information. If I set a break point in “operator<<” function, it breaks. The restore settings function looks like this: QSetting settings; QVariant var = settings.value("references/ref1"); ReferenceT reference = var.value<ReferenceT>(); The reference variable does not contain any of the stored information, just the default parameters from the structure initialization. Secondly, if I set a break point to the “operator>>” function, it is never called. Does anybody spot any flaws in the implementation? Thanks and cheers!

Viewing all articles
Browse latest Browse all 18427

Trending Articles