Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, March 2002
AW: Need for speed vs. QApplication::processEvents()


Message 1 in thread

processEvents has a default timeout of 3 seconds,
that means if you have a lot of events in your eventloop,
the processEvent returns only if the eventLoop is empty or
after 3 seconds.

Maybe it is better for you to use:
qApp->processOneEvent();
or just reduce the timeout to a smaler number if that helps...
qApp->processEvents(10);

-----Ursprüngliche Nachricht-----
Von: mh [mailto:crapsite@gmx.net]
Gesendet: Dienstag, 05. März 2002 11:23
An: qt-interest@trolltech.com
Betreff: Need for speed vs. QApplication::processEvents()


Hi,
in my app I have a couple of imagefilters (blur,rotate and the like).
Since those operations may take a while, I'm using the following approach:

<pseudo code>
bool SomeFilter::applyFilter(QImage* image)
{
  int progress;//range 0 - 100
  while(processing_image)
  {
    //do lots of stuff here
    if(user_stopped_the_show)
      return false;
    if((progress % 10) == 0)
    {
      emit signalProgress(progress);
      qApp->processEvents();
    }
  }
  return true;
}

signalProgress(int) is connected to a slot in a QMainWidget derived class, 
which updates a QProgressWidget. There's also a stop button to abort the 
operation. This works rather well, however, the performance drops enormously

just because of this qApp->processEvents() call. If I let applyFilter() 
block, it's more than three times faster. Does someone know a faster 
(non-blocking) method or has some ideas how to speed this up?
I'm using Qt2.3.1 (no thread support).

Thanks
Michael

--
 [ signature omitted ] 

Message 2 in thread

Ebner Andreas VA Mechatronics + others, Dienstag, 5. März 2002 12:06:
> processEvents has a default timeout of 3 seconds,
> that means if you have a lot of events in your eventloop,
> the processEvent returns only if the eventLoop is empty or
> after 3 seconds.

> Maybe it is better for you to use:
> qApp->processOneEvent();
> or just reduce the timeout to a smaler number if that helps...
> qApp->processEvents(10);

>(ii) don't call qApp->processEvents() too often. (A call every 1/10th
>of a second will

Aha, I thought, that I was calling qApp->processEvents() between 10 and 20 
times (depending on the filter); however, a qDebug() revealed, that I was 
calling it some hundred times due to a bug ;-(

Now some of my filters are up to 10 times faster :-)
Thanks for bringing me back on track,

Michael