The 11th plague of Egypt
25th August 2011, 13:49
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)
{
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;
}
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)
Or should I pass the QDataStream altogether?
bool someFunction(QDataStream out)
BTW does the file need to be closed at the end of the function?
Right now I'm using this code to open the file and write to it.
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;
}
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)
Or should I pass the QDataStream altogether?
bool someFunction(QDataStream out)
BTW does the file need to be closed at the end of the function?