// 监控文件夹 void UpdateService::Monitor() { QString sPluginsPath = QString("%1/new").arg(QApplication::applicationDirPath()); m_pluginWatcher = new QFileSystemWatcher(); m_pluginWatcher->addPath(sPluginsPath); // 添加监视文件的路径 connect(m_pluginWatcher, SIGNAL(directoryChanged(QString)), this,SLOT(TriggerDirectoryChanged(const QString &))); } void UpdateService::TriggerDirectoryChanged(const QString &strpath) { //strpath为监视文件路径 }
需要添加头文件
#include <QFileSystemWatcher>