How find my log file is changed ?
-
wrote on 4 Jul 2013, 06:46 last edited by
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?
-
wrote on 4 Jul 2013, 08:28 last edited by
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
}
@ -
wrote on 4 Jul 2013, 09:14 last edited by
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? -
wrote on 4 Jul 2013, 10:42 last edited by
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.
???
-
wrote on 5 Jul 2013, 15:26 last edited by
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.
-
wrote on 7 Jul 2013, 05:08 last edited by
not any solution?
-
wrote on 8 Jul 2013, 12:50 last edited by
I told you what goes wrong already... now go and implement that:)
1/10