Results 1 to 4 of 4

Thread: Best use of QFileSystemWatcher for a custom directory tree

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation Best use of QFileSystemWatcher for a custom directory tree

    Hi,
    I have a custom widget to list a multiple directory tree with a root item for each directory using a custom name.
    All works very nice and all the needed features is implemented but only one thing is missing which needs some thinking : the file watcher.
    How to add the file watcher correctly to manage the real time update of the tree to be like the disk ?
    Is it good to add one QFileSystemWatcher on each item of the tree ?
    If a parent folder is removed, the children watcher will be called ?
    Thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Best use of QFileSystemWatcher for a custom directory tree

    I would use one watcher and handle adding/removing directories as needed.

    Though I am wondering if you can't use a QFileSystemModel instead.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Best use of QFileSystemWatcher for a custom directory tree

    I've read (somewhere) that using QFileSystemWatcher can miss file system changes for a wide array of reasons. From what I recall, the best practice is (if critical that you catch all changes) to use QFileSystemWatcher but also scan the filesystem on a regular interval to ensure you find any changes you may have missed.

    QFileSystemWatcher uses the underlying OS's file system notification API's and there are any number of reasons why an app may not be informed of changes, etc. Don't want to scare you off, but just wanted you to be aware of the potential pitfalls, etc.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  4. #4
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Best use of QFileSystemWatcher for a custom directory tree

    Works fine the method using one QFileSystemWatcher and add all paths to call one Refresh() function.
    Only one issue I have actually is if I have one item editing and the refresh is called, the edit action is stopped because the refresh actually clear all and add.
    One option is to keep the actual item in edit mode to set him edit again but the best solution is surely to not clear all to add but check what is needed to remove and what is needed to add.
    For that I only see the method using 2 pass : First, find what is needed to remove checking if path exists and Second, Add item if not already added.
    Last edited by Alundra; 16th March 2017 at 03:58.

Similar Threads

  1. QFileSystemWatcher locks directory
    By NehaGupta in forum Qt Programming
    Replies: 0
    Last Post: 3rd September 2014, 13:42
  2. Replies: 0
    Last Post: 23rd December 2013, 12:31
  3. getExistingDirectory doesn not expand directory tree
    By franco.amato in forum Qt Programming
    Replies: 4
    Last Post: 16th April 2013, 04:40
  4. How to list the ftp directory in tree widget?
    By Gokulnathvc in forum Newbie
    Replies: 4
    Last Post: 18th October 2012, 05:08
  5. nsis script question: directory tree
    By vonCZ in forum General Programming
    Replies: 3
    Last Post: 28th November 2008, 00:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.