@stampede: Well, if dir.entryList() returns the list of files in alphabetical order, that's one advantage over using the QSet if you want to display the files to the user. QSet stores entries in whatever order the internal hashing determines, so iterating over the contents of the QSet will not return an alphabetical list, even if they were inserted in alphabetical order. If you wanted to display the current contents in alphabetical order, you'd have to copy the QSet into a QStringList, then sort the list. This isn't so bad, since QString instances with the same values are shared.

So let's use the best of both our ideas - keep the current directory contents as a list, but use sets to determine what has changed:

Qt Code:
  1. void MyClass::directoryChanged( const QString & path )
  2. {
  3. const QDir dir(path);
  4. QStringList newEntryList = dir.entryList();
  5. QSet<QString> newDirSet = QSet<QString>::fromList( newEntryList );
  6. QSet<QString> currentDirSet = QSet<QString>::fromList( _currentEntryList );
  7.  
  8. // Files that haven't changed
  9. QSet<QString> sameFiles = currentDirSet & newDirSet;
  10.  
  11. // Files that have been added
  12. QSet<QString> newFiles = newDirSet - currentDirSet;
  13.  
  14. // Files that have been removed
  15. QSet<QString> deletedFiles = currentDirSet - newDirSet;
  16.  
  17. // and update the current set
  18. _currentEntryList = newEntryList;
  19. }
To copy to clipboard, switch view to plain text mode