I'm a bit stuck in opening a file and modify it in Qt. I have got a file that has some contents. Now I want to open it and add a few more lines to it.
For example, here I open the file
void MainWindow::on_pushButton_readlog_clicked()
{
QString filename = "logfilename.txt";
QFile originalFile(filename);
if(!originalFile.open(QIODevice:: QIODevice::ReadWrite))
{
qDebug () << "Error opening Log file: "<<originalFile.errorString();
return;
}
else
{
QTextStream instream(& originalFile);
QString line = instream.readLine();
while(!instream.atEnd())
{
QString line =instream.readLine(); // I can read line by line
qDebug()<<line;
}
originalFile.close();
}
}
Basically here I want to retain all the contents of the file but add two extra texts in the first two lines: Line 1: "Name: ODL12" Line 2: "Device ID: 45R"
Looks like I need to "append" but dont know how to do it in Qt