file - Qt signal driven tail program -


i'm looking create simple 'tail' type program prints out new lines appended onto file. instead of polling file stat updated modified date, there way catch signal when:

  1. the file has been appended to
  2. the file has been renamed
  3. a new file of given name appears

those 3 requirements need design for. found qfilesystemwatcher give me signal these 3 (i think)...but signal simple...no details has changed still have call stat. way info qfilesystemwatcher?

maybe looking qfilesystemwatcher , filechanged signal.

you hold qhash<qstring, qfileinfo> in application, mapps filepath qfileinfo. in slot connected qfilesystemwatcher::filechanged(const qstring & path) signal create qfileinfo changed file , compare 1 in hash. after set new qfileinfointo hash.

// myapplicationobjec.h class myapplicationobject  {     // ... private:     qhash<qstring, qfileinfo> m_fileinfos; };  // myapplicationobjec.cpp  // slot connected qfilesystemwatcher::filechanged signal void myapplicationobject::filehaschanged(const qstring & path) {     qfileinfo newfileinfo(path);     qfileinfo oldfileinfo(m_fileinfos.value(path));      // compare size example     if (newfileinfo.size() != oldfileinfo.size()) {         // if file size has changed     }       // replace old file info new file info     m_fileinfos.insert(path, newfileinfo); } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -