0

I am a newbie to QT and at the moment struggling with "read and write CSV file from QT" I have 4 questions with it. I have read the link of Parsing through a csv file in Qt, but doesn't really answer my questions.

Suppose i have the CSV file as:

1,2,3,

4,5,6,

7,8,9,

10,11,12,

13,14,15,

16,17,18,

  • how do you display number "5" in qDebug?
  • how to read number "7", "8", "9" at the same time?
  • how to replace number "12" with "50"?
  • how to replace number "13", "14", "15" with, "73", "74", "75"?
  • and how to add a new line after number"18"?

Thank you very very much for your help! ^_^

Community
  • 1
  • 1
  • Possible duplicate of [Parsing through a csv file in Qt](http://stackoverflow.com/questions/27318631/parsing-through-a-csv-file-in-qt) – stefaanv Mar 08 '16 at 13:45
  • It does answer your first concern: reading a CSV file in Qt. I hope you know how to write a file in Qt and how to manipulate data in C++/Qt. It is not the intention that we write your assignments. – stefaanv Mar 08 '16 at 14:16
  • Hi stefaanv, thank you for your comment. To be honest i'm not really sure how to manipulate the file. The link you gave to me is to read the column. instead, i would like to know how to read the row. By the way, it is not an assignment or a project. it just for self-learning. :) – Kuroyuki Hikari Mar 08 '16 at 14:24

1 Answers1

1

It is so old but I want to answer for future reference.

1-) You can show 5 in qDebug() using readLine() and split() functions.

...
        QByteArray line = file.readLine();   //I assume you already created reading stage.
        qDebug()<< (line.split(',').first[1]); //This prints every second character of each line.

2-) As I mentioned in the previous question,

QByteArray line = file.readLine();   //I assume you already created reading stage.
       qDebug()<< (line.split(',')); //This prints every line

3-4) I don't know -not sure- whether they can be changed or not. Because you need the exact location of values that you want to change, maybe QAbstractItem or any other Item classes may help.

Lady Be Good
  • 253
  • 2
  • 12