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:
- the file has been appended to
- the file has been renamed
- 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 qfileinfo
into 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
Post a Comment