// 監控文件夾 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>