Results 1 to 2 of 2

Thread: Detecting errors with QTextStream and QFile

  1. #1
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Detecting errors with QTextStream and QFile

    Hi All,

    I'm using QFile and QTextStream to log data from a server application.

    My problem is I want to be able to rotate out the log files using an external program.

    When the log file gets removed, how can I detect that I need to re-open it from the app?

    Calling fileExists() with every write to the log seems horribly time consuming.

    file->error() doesn't return an error in the above case, neither does textstream->status(). The log file is not there, but no new one is created, and the data supposedly being written is just lost!

    Any ideas?

    Thanks.

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

    Default Re: Detecting errors with QTextStream and QFile

    This is probably OS specific.
    On linux, if you have a handle to an open file, and that file is removed somehow... the OS does not really remove the file until all open file handles are closed.
    So your app can indead continue happily to use the file. It still does exist as the app's handle keeps it alive. New commands like "ls" will not show the file, as they do not have an open handle...

    If you want to make sure the that a file has not been "removed" (from the directory), you have to either check (e.g.) with QFile::exists() or you might wish to watch it with QFileSystemWatcher.

    The more efficient way would be to use QFilesystemWatcher.
    HTH

Similar Threads

  1. QFile, QTextStream
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 12th January 2008, 19:40
  2. QTextStream + QFile issue
    By trueneo in forum Qt Programming
    Replies: 3
    Last Post: 22nd September 2007, 15:16
  3. QFile, QTextStream, seek()
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 29th September 2006, 15:07
  4. QSettings vs (QFile + Qtextstream)
    By nupul in forum Newbie
    Replies: 5
    Last Post: 10th April 2006, 07:26

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.