How to add file save functionality to a Qt application ?
-
Hi,
I am presently developing an application that allows the user to draw and test a Petri Net diagram. I am using the graphic View framework.
I want to add to this application the capability to save (Shift+Ctrl+S) a drawn diagram as a file on the disk and to restore (Ctrl + O) it later.
Is there an easy way to do that ? If I have to use XML, is there an XML-based language to do such as operations with diagrams ? -
There are whole applications doing that but however.
If I would do it I would use some kind of text file (XML should be good for it) and write my own syntax because I have to read it again and would be able to do so. If you want to interchange with other software you have to have a look at their file formats. It would also be possible to write simple text files with the connections if that is suiteable for you and you can save the overhead of an XML file. -
I guess you already have a class or data struct to represent your diagram internally. You could just serialize this data using "QDataStream":http://qt-project.org/doc/qt-4.8/qdatastream.html or "boost::serialize":http://www.boost.org/doc/libs/1_51_0/libs/serialization/doc/index.html . Examples on how to serialize your data and on how to read it back into your internal data are provided in both links. I'm not sure about QDataStream but boost::serialize also provides versioning which comes in quite handy if you have to modifiy the data struct or class you're serializing and you already have released your product. This way you can support newer and older versions of your serialized data simultaniously.
-
It's Ok I used XML and it works well :)