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. CSV file from QT
Forum Update on Monday, May 27th 2025

CSV file from QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 3.5k 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.
  • K Offline
    K Offline
    khalistan
    wrote on 19 Mar 2016, 10:51 last edited by
    #1

    if I have data. For example lets say char name="Sikh";
    and int old="600";
    How I can create CSV file , with these value inside?
    Sikh as header and 600 as value ..
    Please help me how to create csv file from QT gui programming .
    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 19 Mar 2016, 10:55 last edited by mrjj
      #2

      hi
      something like

      QString filename="c:/Data.txt";
      QFile file( filename );
      if ( file.open(QIODevice::ReadWrite) )
      {
          QTextStream stream( &file );
          stream << name <<  "," << old << endl;
      }
      file.close();
      

      This make only one line in text file so you need a loop where you
      take the name, value and write to file from your list or where u have data since
      you only show 2 variables. (name, old)

      1 Reply Last reply
      3
      • K Offline
        K Offline
        khalistan
        wrote on 19 Mar 2016, 11:40 last edited by
        #3

        ja thanks,,,.. but I want to create csv file. (csv format excel).

        M 1 Reply Last reply 19 Mar 2016, 11:46
        0
        • K khalistan
          19 Mar 2016, 11:40

          ja thanks,,,.. but I want to create csv file. (csv format excel).

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 19 Mar 2016, 11:46 last edited by mrjj
          #4

          @khalistan
          hi, ok
          but CSV file mean COMMA SEPARATED VALUES
          and the sample create that.
          sikh,600

          that is a CVS file. !

          So you must be more clear of that the output must be.
          maybe save one from exec and look in it using editor.

          EXEL likes to use tab instead of "," sometimes.

          But again, the sample can create any type of text output you want but you
          must first understand yourself what kind of format you intend to output.

          When that is clear to you , simple change the line
          stream << name << "," << old << endl;
          to match that format and you have your file.

          also just change
          String filename="c:/Data.txt";
          to
          String filename="c:/Data.csv";
          if u need that extension.

          .

          1 Reply Last reply
          2
          • K Offline
            K Offline
            khalistan
            wrote on 19 Mar 2016, 11:54 last edited by
            #5

            es ist gut.... danke ..... Thanks for help

            M 1 Reply Last reply 19 Mar 2016, 12:11
            0
            • K khalistan
              19 Mar 2016, 11:54

              es ist gut.... danke ..... Thanks for help

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 19 Mar 2016, 12:11 last edited by
              #6

              @khalistan
              super.
              Keine Ursache
              :)

              1 Reply Last reply
              1

              5/6

              19 Mar 2016, 11:54

              • Login

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