[Qt-interest] What is the use of QCoreApplication::processEvents()
Ankit Agarwal
ankit17.ag at gmail.com
Mon Apr 6 12:29:59 CEST 2009
Hi,
As far as my knowledge stands,
Qt puts all the events in a Queue and processes it sequentially while user
may keep doing other tasks. This may sound a little odd but things are
processed at a very high speed.
If you call QCoreApplication::processEvents, then the Qt engin shall process
all the pending events in the queue before proceeding.
You may check out the following link for further details:
http://doc.trolltech.com/qq/qq27-responsive-guis.html
On Mon, Apr 6, 2009 at 4:04 PM, shariff <shariff at mic.co.in> wrote:
> 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.
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
--
Regards,
Ankit Agarwal
SW Engineer
Vegayan Systems
email : ankit_agarwal at vegayan.com
Blog : http://ankit17.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090406/422d6d59/attachment.html
More information about the Qt-interest-old
mailing list