Results 1 to 3 of 3

Thread: How to Read a file only when it has been modified?

  1. #1
    Join Date
    Apr 2013
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default How to Read a file only when it has been modified?

    Hi there.

    I need someone who can help me

    Here's the problem.

    I want to read a file and show it on the lineedit.

    When the file is modified, i have to read it and update the lineedit to show what has been changed.

    How can i solve this problem?

    Or Do i have to read the file repeatdly using QThread even though there wasn't any changes?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to Read a file only when it has been modified?

    Use QFileSystemWatcher and connect to fileChanged(const QString & path) signal
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to Read a file only when it has been modified?

    I want to read a file and show it on the lineedit.
    When the file is modified, i have to read it and update the lineedit to show what has been changed.
    A single line file? Hardly seems worth computing what has changed.

    Aside from Santosh's suggestion you could use a QTimer to trigger a check, say once a minute, to see if the file has changed (QFileInfo::refresh() and QFileInfo::lastModified()). Whether the potential time lag is suitable is entirely down to your requirements. Certainly no threads involved though.

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. Check file is modified?
    By mamyte03@gmail.com in forum Qt Programming
    Replies: 6
    Last Post: 20th September 2007, 14:03
  3. Retrieving modified date of file using QHttp
    By hardgeus in forum Qt Programming
    Replies: 9
    Last Post: 4th December 2006, 00:20
  4. Check if a file has been modified
    By Dark_Tower in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 22:27
  5. How to link modified file
    By awalesminfo in forum Newbie
    Replies: 4
    Last Post: 22nd March 2006, 18:24

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.