QT creator: write to text file without overwriting what is currently inside

May 29, 2015 at 7:04am
I want to know how to write to a file but NOT overwrite what is in the file. I know when I'm not using QTcreator I would do this

 
 os.open(filename.c_str(), std::ofstream::out | std::ofstream::app);


but in QTCreator it's a little different and I can't use what I have exactly up there. This is what my code for the file looks like in QT

 
file.open(QIODevice::WriteOnly);


when I try adding "std::ofstream::out | std::ofstream::app" at the end of "QIODevice::writeOnly" I end up getting a bunch of errors.

What could I do to write to a file and not overwrite what is currently in it?

Thanks
May 29, 2015 at 7:28am
Try using QFile instead of QIODevice.

This does not append, but should be good enough to get you headed in the right direction.
QFile::WriteOnly | QFile::Text
May 29, 2015 at 7:37am
Thank you so much!!! I got it working by adding
 
QFile::Append

after the other QFiles.

for some reason when I tried to add that after QIODevice instead and added QFile::Append it wouldn't work.
Topic archived. No new replies allowed.