Solved: How to export points data to txt or csv file?
-
Hi,
You can use "QFile":http://doc.qt.digia.com/qt/qfile.html for such operation. There is detailed description which tells you how to store information in file with use of QTextStream
copy of documentation
@
QFile file("out.txt");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;QTextStream out(&file); out << "The magic number is: " << 49 << "\n";
@
-
Have a look at the "QDataStream":http://qt-project.org/doc/qt-4.8/qdatastream.html class, it can be used to serialize lots of Qt Data Types. For a complete list of all the supported data types see "here":http://qt-project.org/doc/qt-4.8/datastreamformat.html (QPoint is supported).
-
[quote author="KA51O" date="1351151603"]Have a look at the "QDataStream":http://qt-project.org/doc/qt-4.8/qdatastream.html class, it can be used to serialize lots of Qt Data Types. For a complete list of all the supported data types see "here":http://qt-project.org/doc/qt-4.8/datastreamformat.html (QPoint is supported).[/quote]
For outputting to a .txt or .csv file, I would not use QDataStream. It produces binairy output. Very useful, but not if you want to produce standard text files... [[doc:QTextStream]] is your friend, as guziemic already showed in his first reply.
-
Hmm, you're right. I just like the serialization classes like QDataStream or boost::serialization better because they also offer versioning which might come in handy later, when code and output changes but you still have to support the older version as well.
"boost::serialization":http://www.boost.org/doc/libs/1_51_0/libs/serialization/doc/index.html also offers output in xml or text format instead of binary format, so maybe this can be considered. There are "five different archive types":http://www.boost.org/doc/libs/1_51_0/libs/serialization/doc/archives.html#archive_models which result in different output formats.Of course if this is not used in a product that must be supported over a longer time period QTextStream is the simplest option.
-
If the file is only meant for your own application, I agree with KA510. However, there are many occasions where you'd like to exchange data with an already existing application. If that other application accepts .csv, then that is a viable option. That has nothing to do with for how long the product has to be supported for.