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)

    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)
        def _new_notification(self, path):
            print 'file changed'

    Am I doing something wrong ?

    Thx !

  • Lifetime Qt Champion


    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 the paths object.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.