Cannot append to QFile using QIODevice::Append
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?
Code:
log = new QFile( filePath
+ "/variant.log");
// Create a new file called variant.log Q_CHECK_PTR( log );
if( !log->isOpen() )
return 1;
stream
= new QTextStream( log );
// Create a stream so that we can write to the fileQ_CHECK_PTR( stream );
return 0;
Code:
if( log->isWritable() )
*stream <<
QDateTime::currentDateTime().
toString("dd.MM.yy hh:mm:ss.zzz") <<
": " << theError <<
"\n";
Re: Cannot append to QFile using QIODevice::Append
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)?
Re: Cannot append to QFile using QIODevice::Append
Very sorry, I didn't mention that the code does work, but it overwrites, not append. Editing post now.
Re: Cannot append to QFile using QIODevice::Append
Does someone think this is a Qt bug?
Re: Cannot append to QFile using QIODevice::Append
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.