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. String list parsing or serializing
Forum Updated to NodeBB v4.3 + New Features

String list parsing or serializing

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.0k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    paulanon
    wrote on 20 Oct 2011, 02:43 last edited by
    #1

    Hi, I was wondering if Qt has a convenient way to take an object, like QStringList or list of int vectors and output to a file and read it back in.

    E.g.

    @
    QString qs := "( (1,2), (3,4), (5,6))" <--> QStringList list := { "1,2", "3,4", "5,6" } <--or maybe --> vector< vector<int>> vlist := { {1,2}, {3,4}, {5,6} }.
    @

    Doesn't have to be complicated, but I'm thinking boost::serialization might be close to what I want.

    Thanks, in advance.

    [EDIT: code formatting, Volker]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on 20 Oct 2011, 03:01 last edited by
      #2

      There are a number of options for serializing data to a file. The "proper one" would depend on what you intend to use the file for (i.e., whether it's designed to be easily edited by hand, or human readable, or whether it's for data storage, or saving settings data, or whatever.)

      You could look in to QDataStream or QTextStream along with QFile to store the items. Both of those can serialize the main data types in Qt relatively easily. You could also look at QSettings if the intent is to save some data for later.

      Also there's all sorts of options for reading and writing XML files (which are technically text files), should that appeal to you.

      If you can give some more detail as to what you'd like to do, we can probably guide you in the happiest direction!

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        paulanon
        wrote on 20 Oct 2011, 03:29 last edited by
        #3

        I'm interested in a simple to use and human legible/editable; I consider xml as not human legible; well, not simple.

        A specific one would be
        @
        vector< vector<int>> list = { {1,2}, {3,4,5} }.

        cout << list; //outputs: ( (1,2), (3,4,5) )
        @

        I may also want to convert vector
        @< vector<QString>>@
        or QStringList.

        Thank you!

        [edit: @ tags added, please add them around your code, Eddy]

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 20 Oct 2011, 05:43 last edited by
          #4

          In that case, Qt does not have anything ready-to use that meets your specifications. It can of course be easily used to create something like this.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on 20 Oct 2011, 05:59 last edited by
            #5

            you can overwrite the streaming operators to support std:ostring for QString andf QStringList.
            Then it should work :-)

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0

            1/5

            20 Oct 2011, 02:43

            • Login

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