How find my log file is changed ?
-
are you looking for something like "this":http://qt-project.org/doc/qt-4.8/qfilesystemwatcher.html#fileChanged?
-
@
QFileSystemWatcher* watcher = new QFileSystemWatcher;
watcher->addPath( <path-to-file> );
connect(watcher, SIGNAL(fileChanged(const QString &)), this, SLOT(onFileChanged(const QString &)));...
void onFileChanged(const QString &)
{
... //do whatever you want on file change
}
@ -
I try this code but when change this file not response any thing.
@
void MainWindow::initiallize()
{
QFileSystemWatcher* watcher = new QFileSystemWatcher;
watcher->addPath("D:/a.txt");
connect(watcher, SIGNAL(fileChanged(const QString &)), this, SLOT(onFileChange(const QString &)));
}....
void MainWindow::onFileChanged(const QString &)
{
qDebug()<<"ok-";
}@
-
did you specify onFileChanged() as slot?
what did connect() return?
are you sure that the contents of the file have changed after the connect statement? -
Good apps store their data into a temporary file, delete the existing one and then rename the temporary to the (now no longer) existing name. Such a sequence does not trigger a filechanged since -- you guessed it -- the file never changes.
So go for the directoryChanged signal instead and validate that the file you care about has changed in that slot.
-
I told you what goes wrong already... now go and implement that:)