I tried to save some info to the text file using QTextStream. The code is given below:
QFile fi(QString("result.txt"));
fi.remove();
if(!fi.open(QIODevice::Append)) {
qDebug()<<"Cannot open file!";
return -1;
}
QTextStream ts(&fi);
float num = 1, error = 2;
ts<<"num="<<num<<"\t"<<"error="<<error<<endl;
However, the code does not work. The file is created, but nothing is written, i.e., the file is empty.
After some research, I found that I should change the open mode to QIODevice::Text | QIODevice::Append to make the code work. Otherwise the "\t" character must be removed. Does it mean that the QIODevice::Text is designed specifically for the special characters such as "\t" to work in writing to files?