为什么 QFileSystemWatcher 会发出多个信号?而 QFileInfo 首次写入零文件大小

Why does QFileSystemWatcher emit multiple signals? and QFileInfo for the first time writes a zero file size

本文关键字:QFileInfo 文件大小 QFileSystemWatcher 信号 为什么      更新时间:2023-10-16

当文件被更改时,信号应该触发 1 次,但对我来说它工作了几次。

设置功能中,我要求尺寸,打印

parser::parser(QObject *parent) : QObject(parent)
{
setings();
qDebug()<< baseWay <<"n";
fsWatcher = new QFileSystemWatcher();
fsWatcher->addPath( baseWay + "auth.log" );
QObject::connect(fsWatcher, SIGNAL( fileChanged(QString) ), this, SLOT( changed(QString) ));
}

更改文档后,信号处理 2 次,尽管我保存了文档并更改了 1 次。

void parser::changed(const QString &flName)
{
QFileInfo qfi(flName);
qDebug() << "name = " << flName << "size = " << qfi.size();
}

为什么QFileSystemWatcher会发出2次信号?

为什么 QFileInfo 在第一个请求上生成零大小?

我编辑文件记事本++

问题出在文本编辑器及其处理文件的方法上。