hakermania
12th October 2011, 11:47
Hello.
This library allows you to detect whether a folder or a file has changed.
Specifically, if you watch a file, whatever the change, it will send the signal that the file has changed, but you don't know whether only the content has changed or the file was deleted.
If you watch a folder, it will say you that something has changed only if a file has changed (removed/deleted/renamed) on the top folder you've set (not inside its subfolders), and again, you can't even know what kind of change has been made inside the folder.
What I want to do is to add all the files of the given folder at startup of the program and add/remove any file that has been added/removed from the given folder to a list (for example to a list_widget)
What I've done to the program so far is to add all the files recursively to a list (let's say a QStringList) on startup of a selected folder and then track every single file for changes and also track and all the subfolders of the given one and itself for changes. It works.
The main problem is that it turns sometimes to be very slow if there are too many changes in too many files so as to add to the list every file that is added to the given folder or its subfolders and remove any file from the list if it is removed from the given folder or its subfolders as well.
Deletion is quite easy, because I get the signal that the file changed, I detect whether it exists using the QFile library and if it doesn't it has simply changed and I don't remove it from the list.
Addition is challenging. First of all, I have to detect whether a whole folder has been added or simply (a) file(s). So I list all the subfolders of the given (main) folder and I compare it with the list of all the tracked folders (one-by-one). If there's a folder that doesn't exist on the tracked ones I add it. Then, if there are not differences, I get the files of the folder to a list and I compare it to the list containing all the tracked files. Again, if there's a file that's not present to the list with all the tracked files, its being added.
Well, this is quite complicated but I cannot think of a better way considering that qt don't tell me what kind of change happened automatically.
So, I'd like to see if there's any other better way to do such a thing. I hope I was understandable :P
Thanks in advance for any response!
This library allows you to detect whether a folder or a file has changed.
Specifically, if you watch a file, whatever the change, it will send the signal that the file has changed, but you don't know whether only the content has changed or the file was deleted.
If you watch a folder, it will say you that something has changed only if a file has changed (removed/deleted/renamed) on the top folder you've set (not inside its subfolders), and again, you can't even know what kind of change has been made inside the folder.
What I want to do is to add all the files of the given folder at startup of the program and add/remove any file that has been added/removed from the given folder to a list (for example to a list_widget)
What I've done to the program so far is to add all the files recursively to a list (let's say a QStringList) on startup of a selected folder and then track every single file for changes and also track and all the subfolders of the given one and itself for changes. It works.
The main problem is that it turns sometimes to be very slow if there are too many changes in too many files so as to add to the list every file that is added to the given folder or its subfolders and remove any file from the list if it is removed from the given folder or its subfolders as well.
Deletion is quite easy, because I get the signal that the file changed, I detect whether it exists using the QFile library and if it doesn't it has simply changed and I don't remove it from the list.
Addition is challenging. First of all, I have to detect whether a whole folder has been added or simply (a) file(s). So I list all the subfolders of the given (main) folder and I compare it with the list of all the tracked folders (one-by-one). If there's a folder that doesn't exist on the tracked ones I add it. Then, if there are not differences, I get the files of the folder to a list and I compare it to the list containing all the tracked files. Again, if there's a file that's not present to the list with all the tracked files, its being added.
Well, this is quite complicated but I cannot think of a better way considering that qt don't tell me what kind of change happened automatically.
So, I'd like to see if there's any other better way to do such a thing. I hope I was understandable :P
Thanks in advance for any response!