PDA

View Full Version : Cannot append to QFile using QIODevice::Append



philwinder
14th November 2008, 16:33
Hi,
Using the code below, I cannot get my program to open a text file and append to the end (log file). Instead, it overwrites all the data as if I had just sent a normal ReadWrite parameter. Have I done something wrong?


log = new QFile( filePath + "/variant.log"); // Create a new file called variant.log
Q_CHECK_PTR( log );
if( !log->isOpen() )
if( !log->open(QIODevice::Append | QIODevice::Text)) // open it
return 1;
stream = new QTextStream( log ); // Create a stream so that we can write to the file
Q_CHECK_PTR( stream );
return 0;

if( log->isWritable() )
*stream << QDateTime::currentDateTime().toString("dd.MM.yy hh:mm:ss.zzz") << ": " << theError << "\n";

caduel
14th November 2008, 16:43
Have you checked where your code fails?
Can you open the file? Does the file exist afterwards (or before)? Do you have write permissions? Does it get modified (maybe at the wrong place)?

philwinder
14th November 2008, 17:24
Very sorry, I didn't mention that the code does work, but it overwrites, not append. Editing post now.

philwinder
16th November 2008, 13:24
Does someone think this is a Qt bug?

lyuts
17th November 2008, 10:09
What Qt version do you have? What if you try to compile it with another version of Qt or (just guessing) try to compile it on another platform.
Probably this will help to find out whose bug it is.