Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileSystemWatcher working outside a class but not inside

QFileSystemWatcher working outside a class but not inside

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 576 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GofferG Offline
    GofferG Offline
    Goffer
    wrote on last edited by
    #1

    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 !

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved