Hi,

Thanks for the replies, I have the following code working well,
Qt Code:
  1. void Loader::saveToFile()
  2. {
  3. QString fileName = QFileDialog::getSaveFileName( this, tr("Save File As..."), QDir::homePath(), tr("txt (*.txt)"));
  4. if (fileName.isEmpty())
  5. return;
  6. else
  7. {
  8. QFile file(fileName);
  9. if (!file.open(QIODevice::WriteOnly))
  10. {
  11. QMessageBox::information(this, tr("Unable to open file"), file.errorString());
  12. return;
  13. }
  14. // Need to find a way to clear all present data in file, if the file already exists.
  15. QDataStream out(&file);
  16. out.setVersion(QDataStream::Qt_4_3);
  17. out << channels; // "channels" is a QMap<QString, QString> which has the relevant information already inserted.
  18. }
  19. }
To copy to clipboard, switch view to plain text mode 

The problem I now have is that if I open a file that already exists, I overwrite my data to this file, but any original data that is not overwritten still remains... what I need is a way to delete all original data in the file before I write my new data.

Is there a simple way to delete all data in a file?

Thanks