这是一个用来监控本地文件夹变化的服务
w1146869587
2021-11-08 17b4d2e75514f4e8019e015b2eb3dbc6301ea83a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "mbwatchfile.h"
#include <QDir>
 
CMBWatchFile::CMBWatchFile()
{
    m_pSystemWatcher = NULL;
}
 
CMBWatchFile::~CMBWatchFile()
{
    if( m_pSystemWatcher ){
        delete m_pSystemWatcher;
        m_pSystemWatcher = NULL;
    }
}
 
 
void CMBWatchFile::addWatchPath(QString path)
{
    if( m_pSystemWatcher == NULL ){
 
        m_pSystemWatcher = new QFileSystemWatcher();
        connect(m_pSystemWatcher, SIGNAL(fileChanged(QString)), this, SLOT(fileUpdated(QString)));
    }
 
    // 添加监控路径
    m_pSystemWatcher->addPath(path);
}
 
void CMBWatchFile::fileUpdated(const QString &path)
{
    emit sigFileChange(path);
}