I'm building a save file, I have various functions that need to write to the same file one after the other.

Right now I'm using this code to open the file and write to it.

Qt Code:
  1. bool someFunction(QString fileName)
  2. {
  3. QFile file(fileName);
  4. if(!file.open(QIODevice::WriteOnly)) //sometimes opened in Append mode
  5. return 0;
  6.  
  7. QDataStream out(&file);
  8. out.setVersion(QDataStream::Qt_4_7);
  9. out << //here goes the stuff
  10. return 1;
  11. }
To copy to clipboard, switch view to plain text mode 

So I open the file every time, would it be more efficient to open it just one time and then pass the various functions a pointer, like this ?
Qt Code:
  1. bool someFunction(QFile *file)
To copy to clipboard, switch view to plain text mode 

Or should I pass the QDataStream altogether?
Qt Code:
  1. bool someFunction(QDataStream out)
To copy to clipboard, switch view to plain text mode 

BTW does the file need to be closed at the end of the function?