[Qt-interest] What is the use of QCoreApplication::processEvents()
chandrasekar wagmare
sekarwagmare at gmail.com
Mon Apr 6 14:05:38 CEST 2009
a fine example is my file operation example
const char *str;
QString fileName = "result.txt";
QFile inputFile(fileName);
QString line ;
if(!QFile::exists(fileName)){
printf("error while searching the path ...\n");
return ;
}else if(!inputFile.open(QIODevice::ReadOnly | QIODevice::Text)){
printf("error while loading the file ...\n");
return ;
}else{
QTextStream stream(&inputFile);
do{
line = stream.readLine();
ppc1TestTextEdit->append(QString(" %1").arg(line));
usleep(200000);
qApp->processEvents();
}while(!line.isNull());
}
inputFile.close();
return ;
here without qApp->processEvents(); we cant print the lines one by one ...
On Mon, Apr 6, 2009 at 5:24 PM, Arnold Krille <arnold at arnoldarts.de> wrote:
> Hi,
>
> On Monday 06 April 2009 12:34:13 shariff wrote:
> > Can any one explain me the exact use of
> > void QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags
> flags
> > = QEventLoop::AllEvents )
>
> Sometimes you will want to do heavier work inside one of your functions
> like
> searching a big file or searching in the directory tree. When you do all
> that
> in one big step inside the main gui thread, the gui thread will be blocked
> during that time, so there will be no updates which results in no repaints
> if
> the window gets covered and uncovered but also no updates to for example
> progressbars to show the progress. There are several solutions for this
> with
> different difficulty: (sorted by difficulty, highest first)
> 1) Using a separate thread for your heavy work and send signals/events to
> the
> gui-thread.
> 2) Split up your one big loop into a slot that does just one step and
> reschedules itself in the event-loop either by a QTimer inside your object
> or
> by QTimer::singleShot(). This allows for your work-steps to be part of the
> normal event queue and the gui stays responsive.
> 3) Call QCoreApplication::process() every now and then to process events
> (like
> repainting and button-clicks) inside your heavy work function.
>
> Personally I think that #2 is the cleanest solution unless your work is
> really
> big and can easily run parallel to the gui (so problems bigger than "just"
> searching inside a document) in which case you should to #1...
>
> Have a nice day,
>
> Arnold
>
> _______________________________________________
> 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/d890d27f/attachment.html
More information about the Qt-interest-old
mailing list