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.
bool someFunction
(QString fileName
) {
if(!file.
open(QIODevice::WriteOnly)) //sometimes opened in Append mode return 0;
out << //here goes the stuff
return 1;
}
bool someFunction(QString fileName)
{
QFile file(fileName);
if(!file.open(QIODevice::WriteOnly)) //sometimes opened in Append mode
return 0;
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_7);
out << //here goes the stuff
return 1;
}
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 ?
bool someFunction
(QFile *file)
bool someFunction(QFile *file)
To copy to clipboard, switch view to plain text mode
Or should I pass the QDataStream altogether?
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?
Bookmarks