企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 概述 可见监听文件或目录变更 ## 示例 ``` #include <QCoreApplication> #include <QFileSystemWatcher> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // 创建一个 QFileSystemWatcher 对象 QFileSystemWatcher watcher; // 要监视的目录或文件的路径 QString pathToWatch = "/path/to/your/directory"; // 添加要监视的目录或文件 watcher.addPath(pathToWatch); // 连接文件或目录发生变化时触发的信号到槽函数 QObject::connect(&watcher, &QFileSystemWatcher::directoryChanged, [&](const QString &path) { qDebug() << "Directory changed:" << path; }); QObject::connect(&watcher, &QFileSystemWatcher::fileChanged, [&](const QString &file) { qDebug() << "File changed:" << file; }); qDebug() << "Watching directory:" << pathToWatch; return a.exec(); } ```