Hi

What would the best way be to do this:

I have a QDataStream which saves project data to a file. Currently I do it like this:

Qt Code:
  1. QFile file(file_name);
  2. file.open(QIODevice::WriteOnly);
  3. QDataStream stream(&file); // we will serialize the data into the file
  4. // Now I stream lots of stuff to the stream.
To copy to clipboard, switch view to plain text mode 

However sometimes something goes wrong in the project saving and in that case I still need the original file. One way I can think of doing it is to write out a temp file and when successfull copy it over the current file. But I'm sure there must be a better way.

Can I create the stream and then flush it to the file all at once when everything went alright? Or what is the recommended way to do this.

Thanks,
Jaco