. , , . , QTimer, reset , . 500 . , QFileSystemWatcher , , . , , , . . , :
watcher.addPath(worker->monitoredPath);
QObject::connect(&watcher, SIGNAL(directoryChanged(QString)), this,
SLOT(updateQueue()));
connect(timer, SIGNAL(timeout()), this, SLOT(startProcess()));
connect(this, SIGNAL(processRequest()), thread, SLOT(start()));
...
void MainWindow::updateQueue() {
timer->start(500);
}
...
void MainWindow::startProcess() {
if(!thread->isRunning()) {
emit processRequest();
muteWatcher(true);
}
timer->stop();
}
void MainWindow::muteWatcher(bool toggle) {
if(toggle) {
watcher.removePath(worker->monitoredPath);
} else {
watcher.addPath(worker->monitoredPath);
}
}
void DataProcessor::initialize() {
QDir dir(this->monitoredPath);
dir.setFilter(QDir::NoDotAndDotDot | QDir::Files);
dir.setSorting(QDir::Time);
QList<QString> dFiles;
foreach(QFileInfo file, dir.entryInfoList()) {
if(file.suffix().toLower() == "txt") {
dFiles.append(file.fileName());
}
}
if(dFiles.count() == 0) {
emit muteWatcher(false);
emit finished();
return true;
}
initializeLabel();
}
, , . , " ". , , , , .
, -!