[Qt-interest] What is the use of QCoreApplication::processEvents()

shariff shariff at mic.co.in
Mon Apr 6 12:34:13 CEST 2009


Hi everybody,

Can any one explain me the exact use of 
void QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) 

I have gone through the docs.... but I cannot understand the actual use of it. 
It was used in "Find Files" example in relation with Progress dialog updation.

Code:

QStringList Window::findFiles(const QDir &directory, const QStringList &files,
                               const QString &text)
 {
     QProgressDialog progressDialog(this);
     progressDialog.setCancelButtonText(tr("&Cancel"));
     progressDialog.setRange(0, files.size());
     progressDialog.setWindowTitle(tr("Find Files"));

     QStringList foundFiles;

     for (int i = 0; i < files.size(); ++i) {
         progressDialog.setValue(i);
         progressDialog.setLabelText(tr("Searching file number %1 of %2...")
                                     .arg(i).arg(files.size()));
         qApp->processEvents();

         if (progressDialog.wasCanceled())
             break;

         QFile file(directory.absoluteFilePath(files[i]));

         if (file.open(QIODevice::ReadOnly)) {
             QString line;
             QTextStream in(&file);
             while (!in.atEnd()) {
                 if (progressDialog.wasCanceled())
                     break;
                 line = in.readLine();
                 if (line.contains(text)) {
                     foundFiles << files[i];
                     break;
                 }
             }
         }
     }
     return foundFiles;
 }


What is the link between QProgress bar dialog updation and qApp->processEvents() in the above code? When I commented "qApp->processEvents()" below lines of code is not being executed.

     progressDialog.setCancelButtonText(tr("&Cancel"));
     progressDialog.setRange(0, files.size());
     progressDialog.setWindowTitle(tr("Find Files"));

Thanks in advance

Regards,
Shariff


Confidentiality NoticeThe information contained in this Electronic Message 
and any ATTACHMENTs to this message are intended for the EXCLUSIVE USE of 
the ADDRESSEE(s) and may contain CONFIDENTIAL or PRIVILEGED information. 
If you are not the intended recipient, please notify the SENDER at MIC or
itsupport at mic.co.in immediately and DESTROY all copies of this message 
and any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090406/c5894af5/attachment.html 


More information about the Qt-interest-old mailing list