変更を通知するQFileSystemWatcherクラスがあります。
ディレクトリとその内容の暗号化ハッシュを作成したい場合、これが私が行う方法です: -
void AddToHash(const QFileInfo& fileInf, QCryptographicHash& cryptHash)
{
QDir directory(fileInf.absoluteFilePath());
directory.setFilter(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files);
QFileInfoList fileInfoList = directory.entryInfoList();
foreach(QFileInfo info, fileInfoList)
{
if(info.isDir())
{
// recurse through all directories
AddToHash(info, cryptHash);
continue;
}
// add all file contents to the hash
if(info.isFile())
{
QFile file(info.absoluteFilePath());
if(!file.open(QIODevice::ReadOnly))
{
// failed to open file, so skip
continue;
}
cryptHash.addData(&file);
file.close();
}
}
}
// create a fileInfo from the top-level directory
QFileInfo fileInfo(filePath);
QString hash;
// Choose an arbitrary hash, say Sha1
QCryptographicHash cryptHash(QCryptographicHash::Sha1);
// add all files to the hash
AddToHash(fileInfo, cryptHash);
// get a printable version of the hash
hash = cryptHash.result().toHex();