Hi I've noticed a very strange problem a use QFileSystemWatcher to monitor one folder, when new files are copied to this folder the signal directoryChanged is emitted. I wrote a slot, which works well, it gives me the confidence that when ALL files are copied to the folder only then the right action is taken:

Qt Code:
  1. void DServer::newFiles_()
  2. {
  3. QDir input(QDir::homePath() + "/INPUT DICOM");
  4.  
  5. if(input.count() > lastInput)
  6. {
  7. QTextStream(stdout)<<"not all files" << lastInput <<endl;
  8. lastInput = input.count();
  9. return;
  10. }
  11. else
  12. {
  13. QDir inputDir(QDir::homePath() + "/INPUT DICOM");
  14. QTextStream(stdout) << "BEFORE IF "<<inputDir.count() <<endl;
  15. if(inputDir.count() > 1)
  16. {
  17. QTextStream(stdout)<<"Got all files"<< lastInput <<endl;
  18. inputFiles = getPaths(QDir::homePath() + "/INPUT DICOM");
  19. emit this->_moveFiless();
  20. lastPatientName.clear();
  21. lastInput = 1;
  22. }
  23. else
  24. return;
  25. }
  26. }
To copy to clipboard, switch view to plain text mode 

However this slot
Qt Code:
  1. void DServer::moveFiless_()
  2. {
  3. QString input("/INPUT DICOM");
  4. QDate date = QDate::currentDate();
  5. QTime time = QTime::currentTime();
  6.  
  7. for(int i=0; i<inputFiles.count(); i++)
  8. {
  9. QString old_input_list = inputFiles[i];
  10. inputFiles[i].remove(0,(QDir::homePath().count()) + input.count());
  11.  
  12. int length = inputFiles[i].length();
  13. int startindex = inputFiles[i].lastIndexOf("/",-1) + 1;
  14. QString dir_path = inputFiles[i];
  15.  
  16. dir_path.remove(startindex, length);
  17.  
  18. QDir dir;
  19. if(dir.mkpath(QDir::homePath() + "/DICOM STORAGE/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + dir_path) == true)
  20. {
  21. //anonymize here
  22. anonymous("/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + inputFiles[i], old_input_list);
  23. dir.mkpath(QDir::homePath() + "/TEMPORARY STORAGE/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + dir_path);
  24. date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + input_list[i] + ".tmp");
  25.  
  26. QFile::copy(old_input_list, (QDir::homePath() + "/TEMPORARY STORAGE/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + inputFiles[i] + ".tmp"));
  27. QFile::copy(old_input_list, (QDir::homePath() + "/DICOM STORAGE/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + inputFiles[i]));
  28. QFile::remove(old_input_list);
  29. QTextStream(stdout)<<"source file: "<< old_input_list <<endl;
  30. dir.rmpath(QDir::homePath() + "/INPUT DICOM" + dir_path);
  31. }
  32. else
  33. {
  34. QTextStream(stdout) <<"Couldn't make this dir: ' "<< QDir::homePath() + "/DICOM STORAGE" + dir_path <<endl;
  35. }
  36. }
  37. }
To copy to clipboard, switch view to plain text mode 
doesn't work well, the files from source are copied but they only have from 2.6-3.0 kB, when the original ones have about 80kB, that means the QFile::copy works but not good.