Qsettings trouble
-
Hi, I'm having some problem using Qsetting library..
I have my application and I must save some variables , so that if you reopen the program you don't have to restart from zero.enum otherdata{YES,SURE,OK,OTHER,STUFF,NO};
std::pair<QString,int> mydata[3];
std::vector<MyClass*> myclass;I wasn't able to make it work with this kind of data. Any Hints or Solution?
-
Hi, welcome to the forum.
QSettings operates on QVariant to store/read the data. You need to make your types known to Qt's type system for them to be used as QVariant and they need to have a registered streaming operators to be serialized.
See these docs for more info: Q_DECLARE_METATYPE, Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE, qRegisterMetaTypeStreamOperators.There's also a problem with your last type. Don't save pointers (MyClass*). After your app restart they would point to garbage. Your stream operator for that container should save the actual objects data and recreate the object from that data on load.