PDA

View Full Version : QTextStream appends when run more than once



Prophet
20th June 2012, 19:37
QTextStream stream(&serverList);
stream << document.toString();
serverList.close();

how can i get it to overwrite the file and not append to it

wysota
20th June 2012, 20:32
Don't open serverList in append mode.

Prophet
20th June 2012, 21:27
how would i open it in overwrite ?

<< appends

whats the alternative ?

wysota
20th June 2012, 21:48
Rewind the device before you write to it again or reopen the device.

Prophet
20th June 2012, 22:03
like seek(0)

Prophet
21st June 2012, 16:23
I've tried serverList.seek(0) but with no success i also tried resize but that failed as well



QFile serverList("/stuff/Servers.xml");
if(!serverList.open(QIODevice::WriteOnly | QIODevice::Text))
{
qDebug() << "Failed to open file for write";
}
else
{
serverList.seek(0);
QTextStream stream(&serverList);
stream << document.toString();
serverList.close();
}

Prophet
21st June 2012, 18:24
ok so apparently its not the file thats the problem, its document.toString() that once run again is appended to document.. i have tried to document.clear() after the stream << document.toString() but that still does not solve my issue any thoughts ?