I'm trying to figure out a way to recursively iterate through a directory that is actively getting new files added to it as the program is running. QDirIterator works well to do the initial iteration but it seems there is no way to "refresh" QDirIterator so that it iterates through the directory again and comes up with an updated list of entries. Is there a way to make QDirIterator "refresh" or is there a better way to do what I am trying to accomplish?
Here's a snippet from my code:
QDirIterator dirIterator(directory, QDir::AllEntries);
void MainWindow::on_Button_clicked()
{
if (dirIterator.hasNext()) {
qDebug() << dirIterator.next();
dirIterator.next();ui->imageChip1->setIcon(QIcon(dirIterator.next()));
filename = dirIterator.fileName();
filepath = dirIterator.filePath();
}
}
This code works for any entries that existed in the directory when QDirIterator was initialized but NOT for any entries added to the directory AFTER QDirIterator was initialized.