2

I have a Qt application that creates a qtreeview based on the information of a QDir. Is there a way that if the information on the directory changes (say i add a new file or remove an existing one), the qtreeview is updated?

Thanks! =)

acerqueiro
  • 29
  • 5

1 Answers1

2

To monitor file system changes you can use QFileSystemWatcher

Roman Saveljev
  • 2,544
  • 1
  • 21
  • 20
  • Thanks @savelkev I'm doing this `QFileSystemWatcher watcher; watcher.addPath("C:/QtTest"); connect(&watcher, SIGNAL(directoryChanged(QString)), mc, SLOT(showModified(QString)));` but nothing is happening, i'm not getting the signal. In the SlOT i have a cout << "hi" << endl, that is not being printed – acerqueiro Aug 03 '12 at 21:45
  • @user1486311 Have you allocated `watcher` so that it lives long enough to actually emit a signal (so, not as a local variable in a function). – alexisdm Aug 03 '12 at 22:01
  • I used example code from http://stackoverflow.com/questions/10044853/how-to-qfilesystemwatcher and it worked for me. I assume you try GUI application, which has nowhere to print STDOUT. Try that example yourself – Roman Saveljev Aug 03 '12 at 22:07
  • I'm using that example, and is not working :S let me give it another try and i'll let you know in a few minutes! @saveljev – acerqueiro Aug 09 '12 at 14:15
  • mm i think that might be an error i'm having @alexisdm, let me check it and i'll let you know – acerqueiro Aug 09 '12 at 14:15