PDA

View Full Version : How to Read a file only when it has been modified?



cactus0830
15th July 2013, 07:24
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?

Santosh Reddy
15th July 2013, 09:58
Use QFileSystemWatcher and connect to fileChanged(const QString & path) signal

ChrisW67
16th July 2013, 07:16
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.