JPNaude
30th June 2010, 06:54
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:
QFile file(file_name);
file.open(QIODevice::WriteOnly);
QDataStream stream(&file); // we will serialize the data into the file
// Now I stream lots of stuff to the stream.
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
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:
QFile file(file_name);
file.open(QIODevice::WriteOnly);
QDataStream stream(&file); // we will serialize the data into the file
// Now I stream lots of stuff to the stream.
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