Reputation: 53191
I created a simple watcher and added a path to it. I connected the watcher's signal to my method:
void CssSetter::watchIfNeeded(const QString& newPath)
{
if(watcher==nullptr) {
watcher = new QFileSystemWatcher(this);
connect(watcher, &QFileSystemWatcher::fileChanged, this, &CssSetter::cssFileChanged);
}
watcher->addPath(newPath);
}
The callback looks like this:
void CssSetter::cssFileChanged(const QString& path)
{
qDebug()<<"CSS "<<path<<" changed!";
QFileInfo css_file(path);
qDebug()<<"[CSS] Watcher: "<<path<<(css_file.isFile()?" exists!":" doesn't exist!");
// Should update CSS file, but fails because it also has `.exists()` checks inside
setCSSFromPath(path);
}
The output is:
csssetter.cpp:81 (void CssSetter::cssFileChanged(const QString&)): CSS "/storage/extSdCard/w98.css" changed!
csssetter.cpp:84 (void CssSetter::cssFileChanged(const QString&)): [CSS] Watcher: "/storage/extSdCard/w98.css" doesn't exist!
csssetter.cpp:24 (void CssSetter::setCSSFromPath(QFile&)): [CSS] "/storage/extSdCard/w98.css" doesn't exist!
The last line comes from the function normally responsible from loading the file if it exists. When I tried to override the control, it didn't work. Reading the file when in the file watcher's callback is not possible.
How can I properly read the file when QFileSystemWatcher
reports that it has changed? Is this intended, or is it a bug?
Upvotes: 0
Views: 1178