Update txt file after clearing line in Qt
I am trying to update the text file after I cleared a line in the file. When I print after the clear the line is actually cleared but when I reopen the txt file the line is still there.
Here is the Code.
Code:
void myAccounts::on_removeB_clicked()
{
myFile
= new QFile("accountsDB.txt");
qDebug()<<"1!!"<<endl;
else
qDebug()<<"3!!"<<endl;
while(!stream->atEnd())
{
line=stream->readLine();
list = line.split(",");
qDebug()<<ui->tableWidget->currentItem()->text()<<endl;
qDebug()<<list[0]<<endl;
qDebug()<<line<<endl;
if(ui->tableWidget->currentItem()->text() == list[0] || ui->tableWidget->currentItem()->text() == list[1])
{
line.clear();
qDebug()<<line<<endl;
myFile->close();
}
}
ui->tableWidget->removeRow(ui->tableWidget->currentRow());
}
Re: Update txt file after clearing line in Qt
I see no instruction to save the new content to the file.
Re: Update txt file after clearing line in Qt
You will have to read the whole file and hold that data in a temp variable, clear the file content, remove the line from the content, and write back the content with the line cleared.