Solved QFileSystemWatcher working outside a class but not inside
-
Hello community,
I've tried the QFileSystemWatcher a while ago and it worked great, today I was trying to use it inside a class but it doesn't seem to work.
working version:
def change(): print 'file changed' paths = [mypath1] fs_watcher = QtCore.QFileSystemWatcher(paths) fs_watcher.fileChanged.connect(change)
If I run this directly inside my interpreter, it works fine and prints whenever I change the file. The next example is not working when the logic is exactly the same :
class Test(object): def __init__(self, paths): super(Test, self).__init__() self.paths = paths fs_watcher = QtCore.QFileSystemWatcher(self.paths) fs_watcher.fileChanged.connect(self._new_notification) def _new_notification(self, path): print 'file changed' Test(paths=[mypath1])
Am I doing something wrong ?
Thx !
-
Hi,
The scope of your ``fs_watcher object is the
__init__
method, it disappears at the end of it. You have to make it a member object like thepaths
object.