Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Solved: How to export points data to txt or csv file?

Solved: How to export points data to txt or csv file?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 5.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    romeo.rbw
    wrote on last edited by
    #1

    Hi...
    I need your help and suggestion. In my application there are some point data (QPointF ), after the program finish, how's to record it in a file?
    Thank you very much.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      guziemic
      wrote on last edited by
      #2

      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";
      

      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        After the program finishes, you're too late: there is nothing left to store, and no code running to do the storing. I'd recommend storing your data during your application run ;-)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          romeo.rbw
          wrote on last edited by
          #4

          Yes, that's right :) I mean like that Mr. Andre.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            KA51O
            wrote on last edited by
            #5

            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).

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              [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.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                KA51O
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    romeo.rbw
                    wrote on last edited by
                    #9

                    Many thank's, finally it works using QTextStream. :)

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved