[Qt-interest] What is the use of QCoreApplication::processEvents()
chandrasekar wagmare
sekarwagmare at gmail.com
Mon Apr 6 12:26:30 CEST 2009
it will complete all the pending events in the slot or any function at the
time it calls ...
for example if u call a slot findtext() inside
u are trying to update a textEdit text() at same time
u are trying to clear in a same slot ... but qt will pend this update()
call and exec when the slot is returned to main event loop ... so only clear
is available not the update of textEdit text() is available to user ....
so to over come this problem of doing all the event function inside
the calling slots we use qApp->processEvents() ... in this example the
* progressDialog.setLabelText(tr("Searching file number %1 of %2...")
.arg(i).arg(files.size()));
*without qApp->processEvents() . only the last text update() will be
available to the user .. because it set the text only after it returns to
main event loop where only the last function call is available ...
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
>
>
--
CHANDRU
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090406/2e4ad069/attachment.html
More information about the Qt-interest-old
mailing list