write csv file

  • Hi i'm trying to write a basic csv file. I have no compilation error but no csv file is created when I run the code, I don't understand why. Can someone help me ? Here is my code

    #include <QFile>
    #include <QStringList>
    #include <QDebug>

    int main( int, char* [] )
    double value1(10);
    double value2(13.2);
    QFile file("./file.csv");
    if (file.open(QFile::WriteOnly|QFile::Truncate))
    QTextStream stream(&file);
    stream << value1 << "\t" << value2 << "\n"; // this writes first line with two columns

  • Qt Champions 2017

    hi and welcome

    On windows
    QFile file("e:/file.csv");

    produced the expected file. So your code works.

    ./ which means current folder in linux would be the debug or release folder,
    not where the source files are.

    You could try with absolute path like
    QFile file("/home/user/file.csv");

  • It works thank you very much!

Log in to reply

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