How find my log file is changed ?
-
Hi .
How find my log file is changed ?
similar too tail -f on linux.Thanks.
-
are you looking for something like "this":http://qt-project.org/doc/qt-4.8/qfilesystemwatcher.html#fileChanged?
-
how i can use this method on background my program.
please help me.thanks.
-
@
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? -
every thing is ok. and connect() return true.
problem is when file changed manually Correctly work this code.
but when changed file with other program and logs created not any event happen.
???
-
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.
-
not any solution?
-
I told you what goes wrong already... now go and implement that:)