本页内容

Utils::FileSystemWatcher Class

class Utils::FileSystemWatcher

FileSystemWatcher 类是一个文件监视器,它在内部使用集中式的QFileSystemWatcher ,并在 Mac OS 上强制执行限制。更多内容...

Header: #include <FileSystemWatcher>
Inherits: QObject

公共函数

FileSystemWatcher(QObject *parent = nullptr)
FileSystemWatcher(int id, QObject *parent = nullptr)

详细说明

设计注意事项

QFileSystemWatcher 的构造和销毁开销较大。可以通过使用集中式监视器来规避此问题。

注意: 通过向构造函数传递一个(任意)整数 id != 0,(目前)仍可 创建多个 `QFileSystemWatcher ` 实例。这使得那些容易超过操作系统限制的监视器能够与其他监视器区分开来(见下文)。

Mac OS 特定情况

在 macOS 上,每个进程在同一时间点可打开的文件句柄数量存在硬性限制(例如,在 Mac OS X Snow Leopard Server 上为 2560,如ulimit -a 所示)。若打开一个或多个用于监视大量目录的.qmlproject ,很容易超过此限制。 其结果是系统随后会发生崩溃,例如当无法再创建线程时。

该类实现了一种启发式策略,确保文件系统监视器在处理.qmlproject 文件时,所使用的文件句柄数量绝不超过可用文件句柄总数的一半。此外,它还将文件句柄数量从rlim_cur 增加到了rlim_max ——main.cpp中的旧代码已失效,详见

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/setrlimit.2.html

的最后一段。

成员函数文档

[explicit] FileSystemWatcher::FileSystemWatcher(QObject *parent = nullptr)

创建一个 ID 为 0、所有者为parent 的文件系统监视器。

[explicit] FileSystemWatcher::FileSystemWatcher(int id, QObject *parent = nullptr)

创建一个文件系统监视器,其ID为id ,所有者为parent 。

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.