Data does not get reflected in real time in Qt TexttEdit widget

Viewed 37

I am trying to scan files and its sub directory , the code from Qt Examples works absolutely fine and displays data with QDebug() . However when i try to it.next() data to a Qlable or textEdit widget , it doesn't show the data in realtime. The data is reflected after the it.hasNext() gets completed. I want to show real time scanning status in the textedit box - Self is new to Qt.

How to show the status for the file being scanned in real time, in the Qt textEdit widget ?

Code is given below .

void  MainWindow::findFilesRecursively(QDir rootDir) {
    QDirIterator it(rootDir, QDirIterator::Subdirectories);
    while(it.hasNext()) {
        qDebug() << it.next();
       //  ui->textEdit->append(it.next());    <<<<<<---- This is note getting updated realtime,
                                                          Data get populated after the scan in complted.
                                                                  
    }
}

Error

enter image description here

1 Answers

This may or may not be your problem, but do you understand what your code is trying to do?

Your debug statement calls it->next(). You then in your commented-out code call it->next() a second time. If your directory only contains a single file, you've already dumped it. The debug statement eats it.

What you need instead:

 QString fName = it->next();
 qDebug() << fName;
 ui->textEdit->append(fName);

I'm not absolutely positive this is your problem, because I don't know if you commented out your qDebug when you ran it or how big your directory is. There might be something else going on.

Related