PDA

View Full Version : Remove a line in a text file



jaca
17th March 2010, 00:47
How to remove a line from a file?


void DeslocaPt::skip(QStringList &l, QStringList &p)
{
QString arqAlt = altEdit->text();
QString line, linesimp;
QFile file(arqAlt);
if(file.open(QIODevice::ReadWrite | QIODevice::Text)){
QTextStream out(&file);
while(!out.atEnd()){
line = out.readLine();
linesimp = line.simplified();
for (int i = 0; i < l.size(); ++i)
if (linesimp.contains(QString("S%1 %2").arg(l.at(i)).arg(p.at(i)))){
line.clear();
}

out << line << endl;
}
}
file.close();
}

I tried to do:

line.clear();
out << line << endl;
I used this command to position

out.seek(out.pos() - line.size() );
result is not satisfactory. Any idea?

jaca
18th March 2010, 22:13
I think there is not a quicker solution to delete a row in a given file. The solution was to add two QFile, one for ReadOnly and another to WriteOnly.