QT笔记- 目录文件夹/文件变更监视类QFileSystemWatcher用法

函数

QFileSystemWatcher类用于监视指定目录文件夹/文件的重命名、移除、删除操作, 当发生这些变更时该类会发出信号。

常用函数如下:

  1. bool QFileSystemWatcher::addPath(const QString & path)
  2. void QFileSystemWatcher::directoryChanged(const QString & path)
  3. void QFileSystemWatcher::fileChanged(const QString & path)

释义

  1. 添加目录, 目录字符串中可以带有文件名及后缀。多次调用,可添加多个不同目录。
  2. 这是一个信号函数,当监视的文件夹包含的一级内容发生变更时,会发出此信号。
  3. 这是一个信号函数,当监视的文件发生内容改变重命名或被删除时,会发出此信号。

示例

QFileSystemWatcher * watch = new QFileSystemWatcher(this);
connect(watch, &QFileSystemWatcher::fileChanged, this, &Form::_changed);
watch->addPath("C:\\Users\\Administrator\\Documents\\untitled7\\a.txt");

_changed()信号函数:

#include <iostream>
void Form::_changed(const QString & path)
{
    std::cout << "Form::_changed - " << qPrintable(path) << std::endl;
}

将目录C:\\Users\\Administrator\\Documents\\untitled7\\a.txt下的a.txt文件删除后,控制台打印出了如下信息:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值