Hey all (out there :).
Which way is the best for writing a custom class to a file in Qt?
Thank you in advance.
Matthias
Hey all (out there :). Which way is the best for writing a custom
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EDIT: Question has been already asked. Serialization with Qt
The best way is to serialize using QDataStream. For a given class
MyClass, you need to define new stream operatorsQDataStreamis already capable of writing several Qt classes, mostly collections and other convenients classes likeQImage, etc…. Note that you cannot serialize any subclass ofQObject. There are reasons :), but limit yourself to the explanation thatQObjectitself doesn’t provide neither copy constructors nor in\out stream functions like the one above.Note that if your custom class derive a class already providing serialization, you need to call the stream operators for this superclass (the same principle as calling the constructor of the superclass when constructing the subclass).