我就是这样初始化观察者的:
QFileSystemWatcher watcher;
bool isWatched = watcher.addPath("../stylesheets/main.style");
if (isWatched) qDebug() << "Stylesheet is being watched.";
connect(&watcher, &QFileSystemWatcher::fileChanged, this, &PCLViewer::updateStyle );但是,当我修改、删除或重命名文件时,我的更新样式函数永远不会被调用!我也尝试过连接插槽和信号,比如:
connect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateStyle(QString)) );updateStyle函数的签名如下:
public slots:
void updateStyle(const QString &path);我用的是ubuntu。
发布于 2016-05-11 16:58:02
插槽函数签名是错误的。我不得不用void updateStyle (QString path);来接电话。
发布于 2020-11-06 00:46:50
如果有人有同样的问题。
试试这个:
QFileSystemWatcher *watcher = new QFileSystemWatcher();
bool beingWatched = watcher->addPath("Enter your path here");
if (beingWatched ) qDebug() << "Being watched";
QObject::connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(handleFileChanged(QString)));我不知道为什么,但你需要创建一个指针,至少在我的系统上,才能发出信号,否则就不能工作。
https://stackoverflow.com/questions/37165497
复制相似问题