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:
void DServer::newFiles_()
{
QDir input
(QDir::homePath() + "/INPUT DICOM");
if(input.count() > lastInput)
{
QTextStream(stdout)<<
"not all files" << lastInput <<endl;
lastInput = input.count();
return;
}
else
{
QDir inputDir
(QDir::homePath() + "/INPUT DICOM");
QTextStream(stdout) <<
"BEFORE IF "<<inputDir.
count() <<endl;
if(inputDir.count() > 1)
{
QTextStream(stdout)<<
"Got all files"<< lastInput <<endl;
inputFiles
= getPaths
(QDir::homePath() + "/INPUT DICOM");
emit this->_moveFiless();
lastPatientName.clear();
lastInput = 1;
}
else
return;
}
}
void DServer::newFiles_()
{
QDir input(QDir::homePath() + "/INPUT DICOM");
if(input.count() > lastInput)
{
QTextStream(stdout)<<"not all files" << lastInput <<endl;
lastInput = input.count();
return;
}
else
{
QDir inputDir(QDir::homePath() + "/INPUT DICOM");
QTextStream(stdout) << "BEFORE IF "<<inputDir.count() <<endl;
if(inputDir.count() > 1)
{
QTextStream(stdout)<<"Got all files"<< lastInput <<endl;
inputFiles = getPaths(QDir::homePath() + "/INPUT DICOM");
emit this->_moveFiless();
lastPatientName.clear();
lastInput = 1;
}
else
return;
}
}
To copy to clipboard, switch view to plain text mode
However this slot
void DServer::moveFiless_()
{
for(int i=0; i<inputFiles.count(); i++)
{
QString old_input_list
= inputFiles
[i
];
inputFiles
[i
].
remove(0,
(QDir::homePath().
count()) + input.
count());
int length = inputFiles[i].length();
int startindex = inputFiles[i].lastIndexOf("/",-1) + 1;
dir_path.remove(startindex, length);
if(dir.
mkpath(QDir::homePath() + "/DICOM STORAGE/" + date.
toString("dd.MM.yyyy") + "/" + time.
toString("hh:mm:ss") + dir_path
) == true) {
//anonymize here
anonymous("/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + inputFiles[i], old_input_list);
dir.
mkpath(QDir::homePath() + "/TEMPORARY STORAGE/" + date.
toString("dd.MM.yyyy") + "/" + time.
toString("hh:mm:ss") + dir_path
);
date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + input_list[i] + ".tmp");
QFile::copy(old_input_list,
(QDir::homePath() + "/TEMPORARY STORAGE/" + date.
toString("dd.MM.yyyy") + "/" + time.
toString("hh:mm:ss") + inputFiles
[i
] + ".tmp"));
QFile::copy(old_input_list,
(QDir::homePath() + "/DICOM STORAGE/" + date.
toString("dd.MM.yyyy") + "/" + time.
toString("hh:mm:ss") + inputFiles
[i
]));
QFile::remove(old_input_list
);
QTextStream(stdout)<<
"source file: "<< old_input_list <<endl;
dir.
rmpath(QDir::homePath() + "/INPUT DICOM" + dir_path
);
}
else
{
QTextStream(stdout) <<
"Couldn't make this dir: ' "<<
QDir::homePath() + "/DICOM STORAGE" + dir_path <<endl;
}
}
}
void DServer::moveFiless_()
{
QString input("/INPUT DICOM");
QDate date = QDate::currentDate();
QTime time = QTime::currentTime();
for(int i=0; i<inputFiles.count(); i++)
{
QString old_input_list = inputFiles[i];
inputFiles[i].remove(0,(QDir::homePath().count()) + input.count());
int length = inputFiles[i].length();
int startindex = inputFiles[i].lastIndexOf("/",-1) + 1;
QString dir_path = inputFiles[i];
dir_path.remove(startindex, length);
QDir dir;
if(dir.mkpath(QDir::homePath() + "/DICOM STORAGE/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + dir_path) == true)
{
//anonymize here
anonymous("/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + inputFiles[i], old_input_list);
dir.mkpath(QDir::homePath() + "/TEMPORARY STORAGE/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + dir_path);
date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + input_list[i] + ".tmp");
QFile::copy(old_input_list, (QDir::homePath() + "/TEMPORARY STORAGE/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + inputFiles[i] + ".tmp"));
QFile::copy(old_input_list, (QDir::homePath() + "/DICOM STORAGE/" + date.toString("dd.MM.yyyy") + "/" + time.toString("hh:mm:ss") + inputFiles[i]));
QFile::remove(old_input_list);
QTextStream(stdout)<<"source file: "<< old_input_list <<endl;
dir.rmpath(QDir::homePath() + "/INPUT DICOM" + dir_path);
}
else
{
QTextStream(stdout) <<"Couldn't make this dir: ' "<< QDir::homePath() + "/DICOM STORAGE" + dir_path <<endl;
}
}
}
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.
Bookmarks