When connecting a QFileSystemWatcher to a custom slot, the slot is executed once and then hangs. The Application doesn't crash and it is still responsive.
#include <QtGui>
#include <QDebug>
class CustomWidget
: public QObject{ Q_OBJECT
public:
{ }
public slots:
void aSlot()
{ qDebug() << "aSlot invoked"; }
};
#include "main.moc"
int main(int argc, char *argv[])
{
CustomWidget wid;
watcher.removePath("/test"); //works as expected if commented out
watcher.addPath("/test");
QObject::connect(&watcher,
SIGNAL(directoryChanged
(QString)) ,
&wid,
SLOT(aSlot
() ) );
return app.exec();
}
#include <QtGui>
#include <QDebug>
class CustomWidget : public QObject
{ Q_OBJECT
public:
CustomWidget(QWidget* parent=0) : QObject(parent)
{ }
public slots:
void aSlot()
{ qDebug() << "aSlot invoked"; }
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
CustomWidget wid;
QFileSystemWatcher watcher;
watcher.removePath("/test"); //works as expected if commented out
watcher.addPath("/test");
QObject::connect(&watcher, SIGNAL(directoryChanged(QString)) , &wid, SLOT(aSlot() ) );
return app.exec();
}
To copy to clipboard, switch view to plain text mode
I am using a mac to run the QTCreator application, and this may be the issue.
I am using an xml file that I am changing while the application runs, I want the extracted values to update some progress bars. It does update once, but then nothing changes after the xml file is changed the second time
Any time I update a file I want the custom slot to be run. It is run the first time and then hangs.
I tested this by adding a second variable of type QFileSystemWatcher which is connected to the same custom slot. The behaviour is the same for both files, it updates once but then nothing.
I assume the problem is with QFileSystemWatcher.
Bookmarks