Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Write into file

Write into file

Scheduled Pinned Locked Moved Brainstorm
11 Posts 6 Posters 9.3k 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.
  • G Offline
    G Offline
    goetz
    wrote on last edited by
    #2

    If you're not in need of a human readable/editable file, I would recommend [[Doc:QDataStream]] together with "operator<<".

    http://www.catb.org/~esr/faqs/smart-questions.html

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

      Thanks for your quick reply.

      The output file should look like this:
      MSH|^~&|LABOR||MEDIKA||201101010032||ORR^O02|7500421|P|2.3|||NE|AL||
      MSA|AA|2714415|
      ORC|OK|7500421^MEDIKA|7500421^LABOR||IP||^^^^||||||||||

      I write the file under win and is reading under unix. Carriage return closes the lines. According the Qt Assistant no input parameter like QString or QQueue at “operator<<”. I guess I can't get rid of the iteration:(

      Is intelligence a blessing or a curse?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #4

        No, of course you need a bit of custom parsing to handle that. QTextStream and QString::split may come in handy.

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #5

          You did not answer the question regarding human readability.

          The questions are:

          must the resulting file be human readable and/or editable

          is the file written using Qt only

          is the file reaad using Qt only

          Answer all of these with yes or no.

          The result will influence the way to store and retrieve the data.

          http://www.catb.org/~esr/faqs/smart-questions.html

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

            Sorry,

            The answers:

            1. yes, it must be editable by vi or nano
            2. yes, under windows
            3. no, reading is under unix

            Is intelligence a blessing or a curse?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #7

              [quote author="arabiata" date="1312982497"]Sorry,

              The answers:

              1. yes, it must be editable by vi or nano
              2. yes, under windows
              3. no, reading is under unix[/quote]

              On Unix you can have Qt too :-)

              Anyways, as the blocker is the "editable by...", I would go like this:

              @
              QStringList sl;
              // fill it somewhere

              QFile file("output.txt");
              if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
              // error processing here
              break;
              }

              QTextStream ts(&file);
              ts << sl.join('|');
              ts << "\r"; // or "\n";
              file.close();
              @

              For the QQueue there is no join() method, you will have to iterate through all the elements:

              @
              QQueue<QString> stringQueue;

              QString delim; // emtpy string
              foreach(const QString &e, stringQueue) {
              ts << delim << e;
              delim = "|";
              }
              ts << "\r"; // or "\n"
              @

              http://www.catb.org/~esr/faqs/smart-questions.html

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

                Volker for president:).
                Thanks

                Is intelligence a blessing or a curse?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mgran
                  wrote on last edited by
                  #9

                  [quote author="arabiata" date="1313005537"]Volker for president:).[/quote]

                  He would make all of us drive a motorcycle while eating muffins and ban rain in general. I'm voting yes!

                  Project Manager - Qt Development Frameworks

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rokemoon
                    wrote on last edited by
                    #10

                    [quote author="mariusg" date="1313049650"][quote author="arabiata" date="1313005537"]Volker for president:).[/quote]

                    He would make all of us drive a motorcycle while eating muffins and ban rain in general. I'm voting yes![/quote]
                    I'm voting yes too :-D! In Moscow right now is rain, so ban not prevent.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mlong
                      wrote on last edited by
                      #11

                      And thus, the Muffincycle Party was born with the nomination of it's first candidate. :-)

                      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

                      • Login

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