Results 1 to 5 of 5

Thread: Cannot append to QFile using QIODevice::Append

  1. #1
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

    Qt Code:
    1. log = new QFile( filePath + "/variant.log"); // Create a new file called variant.log
    2. Q_CHECK_PTR( log );
    3. if( !log->isOpen() )
    4. if( !log->open(QIODevice::Append | QIODevice::Text)) // open it
    5. return 1;
    6. stream = new QTextStream( log ); // Create a stream so that we can write to the file
    7. Q_CHECK_PTR( stream );
    8. return 0;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. if( log->isWritable() )
    2. *stream << QDateTime::currentDateTime().toString("dd.MM.yy hh:mm:ss.zzz") << ": " << theError << "\n";
    To copy to clipboard, switch view to plain text mode 
    Last edited by philwinder; 14th November 2008 at 17:26.
    Best Regards,
    Phil Winder
    www.philwinder.com

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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)?

  3. #3
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.
    Best Regards,
    Phil Winder
    www.philwinder.com

  4. #4
    Join Date
    Apr 2008
    Posts
    73
    Thanks
    11
    Thanked 7 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cannot append to QFile using QIODevice::Append

    Does someone think this is a Qt bug?
    Best Regards,
    Phil Winder
    www.philwinder.com

  5. #5
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.
    I'm a rebel in the S.D.G.

Similar Threads

  1. Append mode in QFile
    By Sarma in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2006, 12:47

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.