Results 1 to 5 of 5

Thread: How to read changing file contents

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: How to read changing file contents

    Try using QFileSystemWatcher and connect to the fileChanged() signal. When the signal is sent with the name of the file you are interested in, then you know it has changed. At that point, you can re-read the file.

    When you read the file with QFile, you basically create a copy in memory of the contents of the file at the time you read it. This in-memory data does not change when the file changes, because it is a copy.

    If you want the in-memory data to be up to date, then you need to watch the file for changes (which QFileSystemWatcher will do for you) and re-read the file when you see it has changed. Be sure to close the file after you read it, otherwise the other app that is changing it may not be able to open it if you have it open and locked.
    Last edited by d_stranz; 9th July 2011 at 23:43.

Similar Threads

  1. Read contents from the file using QHTTP Read()?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 21st June 2011, 09:03
  2. Replies: 8
    Last Post: 17th June 2011, 01:35
  3. Display contents of .txt file
    By karmo in forum Newbie
    Replies: 17
    Last Post: 23rd January 2010, 21:39
  4. QTableView and changing how a cell displays its contents
    By BitRogue in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2009, 11:18

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
  •  
Qt is a trademark of The Qt Company.