【问题标题】:QfileSystemWatcher doesn't workQfileSystemWatcher 不起作用
【发布时间】:2016-05-11 14:21:26
【问题描述】:

这就是我初始化观察者的方式:

  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。

【问题讨论】:

  • 到目前为止,代码片段看起来是正确的。请发布更完整的代码示例。
  • 您是否尝试使用文件的完整路径?
  • 是的,我厌倦了完整路径和另一个文件,但都没有用!

标签: qt filesystems filesystemwatcher


【解决方案1】:

如果有人遇到同样的问题。

试试这个:

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)));

我不知道为什么,但您至少需要在我的系统上创建一个指针来发出信号,否则它将不起作用。

【讨论】:

    【解决方案2】:

    槽函数签名错误。我必须使用void updateStyle (QString path); 才能调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多