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. write csv file

write csv file

Scheduled Pinned Locked Moved General and Desktop
write csv
3 Posts 2 Posters 2.0k Views 2 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.
  • E Offline
    E Offline
    ebrion
    wrote on last edited by
    #1

    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
    file.close();
    }
    }

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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");

      1 Reply Last reply
      1
      • E Offline
        E Offline
        ebrion
        wrote on last edited by
        #3

        It works thank you very much!

        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