I am using the above function to write to a file (the application is a nokia mobile application). It works correctly and writes a single line to the file.Code:void Add::saveData() { QFile file("c://WeightTracker.csv"); if (!file.open(QIODevice::WriteOnly)) { //std::cerr << "Cannot open file for writing: " //<< qPrintable(file.errorString()) << std::endl; return; } QTextStream out(&file); qint32 weight = (ui->lineEdit->text()).toInt(); QString date_of_weight = (ui->dateEdit->date()).toString(); out << date_of_weight << "," << weight << endl; }
But I have 2 problems:
1. The data is written when a button is clicked (saveData is a slot connected to a clicked signal). But when I click the button multiple times, the first line is always overwritten (so there is always only 1 row in the file). With every button click, I want new data to be added as a new row.
2. If I enable the following line:
I get the following error: "cerr is not a member of std"; can you please help me resolve this error?Code://std::cerr << "Cannot open file for writing: " //<< qPrintable(file.errorString()) << std::endl;
The project can be found here: [link removed]
Thanks in advance for your help.

Reply With Quote

