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
QtWS25 Last Chance

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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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 last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • K khalistan

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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 last edited by
            #5

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

            mrjjM 1 Reply Last reply
            0
            • K khalistan

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @khalistan
              super.
              Keine Ursache
              :)

              1 Reply Last reply
              1

              • Login

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