Clearing existing file



  • Hi guys,
    Maybe just a trivial question, but I have to write some data to a file (and off course open it again later on). The problem I encounter is that when the file already exists the "old" data in the file will stay there when the new data (that overwrites this) is shorter then the old data. In QFile the only thing I could find is QFile.resize(0); I'm using a QTextStream to fill the data in the file.

    Are there any better ways of doing this? It does work, but IYAM it's not real pretty, or is it?

    Greetz



  • I'm not sure if I understand your issue so I prefer to post a snippet.



  • Try to open the file with QIODevide::Truncate flag like

    @QFile file(path);
    file.open(QIODevice::WriteOnly | QIODevice::Truncate);@



  • [quote author="Sam" date="1359467461"]Try to open the file with QIODevide::Truncate flag.[/quote]

    If the problem persists after that, try to remove the file before writing the new data.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.