【问题标题】:QFileSystemWatcher::addPath recursivelyQFileSystemWatcher::addPath 递归
【发布时间】:2012-09-27 08:52:56
【问题描述】:

大家好,我想使用QFileSystemWatcher 来递归地观察给定目录及其子目录的变化,但是void QFileSystemWatcher::addPath ( const QString & path ) 不允许我这样做,所以有什么想法可以轻松地做到这一点,或者我应该通过以下方式实现它我的自我(提取所有目录和子目录和文件以添加void QFileSystemWatcher::addPaths ( const QStringList & paths ))?

任何帮助将不胜感激。

提前谢谢你。

【问题讨论】:

    标签: c++ qt directory subdirectory qfilesystemwatcher


    【解决方案1】:

    QFileSystemWatcher 类的 documentation 并未声明递归监视是其合同的一部分。因此,正如您所暗示的,我认为一个解决方案可能是自己遍历目录树,将所有子目录及其文件收集在字符串列表中并使用

    void QFileSystemWatcher::addPaths ( const QStringList & paths )
    

    另外,我认为提及您正在使用的 qt 版本可能对您有用,因为根据threadQFileSystemWatcher 正在被弃用,并且应该用新的 api 替换它。

    【讨论】:

    • 您好,谢谢您的回复,正在使用QtSdk-v1_2_1(QT 4.8.1),提供了Old prototype: void QFileSystemWatcher::addPath ( const QString & path ),所以我想我会自己进行,谢谢您再一次.
    • 这是一个example 说明如何使用 QDir 遍历目录。您可以轻松地对其进行调整以满足您的需求。
    • 如果您以这种方式添加子树,需要注意的一件事...根据 QFileSystemWatcher 文档:“默认情况下,某些系统将打开文件描述符的数量限制为 256。”如果我理解正确,这意味着如果有超过 256 个子目录,这种方法在某些系统上会失败。
    猜你喜欢
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多