0

When a file is changed, the signal should fire 1 time, but for me it works several times.

In setings function, I request size and it prints

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

After I change the document, the signal processes 2 times, although I saved the document and changed it 1 time.

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

Why does QFileSystemWatcher give a signal 2 times?

Why does QFileInfo produce a zero size on the first request?

I edit the file Notepad ++

  • Did you test from a different editor? Perhaps notepad? Maybe the double emit is related to how notepad++ is writing the file. – drescherjm Jan 15 '20 at 15:32
  • @drescherjm, notepad fixes, but if the file is overwritten or deleted nothing changes – Roman Khudoberdin Jan 15 '20 at 15:35
  • There are a couple of open bugs on the behavior of QFileSystemWatcher under windows. [https://bugreports.qt.io/browse/QTBUG-41119](https://bugreports.qt.io/browse/QTBUG-41119) and [https://bugreports.qt.io/browse/QTBUG-38757](https://bugreports.qt.io/browse/QTBUG-38757) – drescherjm Jan 15 '20 at 15:43

1 Answers1

0

The problem was in the text editor and its methods of working with the file.