CSV file from QT

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

  • Qt Champions 2017

    something like

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

    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)

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

  • Qt Champions 2017

    hi, ok
    and the sample create that.

    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";
    String filename="c:/Data.csv";
    if u need that extension.


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

  • Qt Champions 2017

    Keine Ursache

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.