You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, May 9th 2005, 1:14pm

use timer->start(0,FALSE) to provide snappy user interface?

i don't understand following descriptions in Qt Manual about QTimer? how can provide a snappy user interface during heavy work?

Quoted

As a special case, a QTimer with timeout 0 times out as soon as all the events in the window system's event queue have been processed.

This can be used to do heavy work while providing a snappy user interface:



QTimer *t = new QTimer( myObject );


connect( t, SIGNAL(timeout()), SLOT(processOneThing()) );


t->start( 0, FALSE );


myObject->processOneThing() will be called repeatedly and should return quickly (typically after processing one data item) so that Qt can deliver events to widgets and stop the timer as soon as it has done all its work. This is the traditional way of implementing heavy work in GUI applications; multi-threading is now becoming available on more and more platforms, and we expect that null events will eventually be replaced by threading.

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

2

Monday, May 9th 2005, 1:57pm

RE: use timer->start(0,FALSE) to provide snappy user interface?

Quoted

Originally posted by intermilan
t->start( 0, FALSE );

The key is that false as the second argument --- that timer will work in a loop.

After Qt processes all events, it will emit the timeout signal and your processOneThing slot will be invoked. When your slot returns, that timer will again wait for all events to be processed and so on until you stop it.

This is similar to calling QApplication::processEvents inside a long loop.

3

Monday, May 9th 2005, 2:49pm

RE: use timer->start(0,FALSE) to provide snappy user interface?

i know,but

Quoted

This is the traditional way of implementing heavy work in GUI applications; multi-threading is now becoming available on more and more platforms, and we expect that null events will eventually be replaced by threading.


i don't understand exactly what these words mean?

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

4

Monday, May 9th 2005, 2:55pm

RE: use timer->start(0,FALSE) to provide snappy user interface?

It means that in this method you perform small steps everytime your application hasn't got anything else to do. It makes a loop like this:

Source code

1
2
3
4
while(1){
    while(event queue not empty) processEventFromQueue();
    performOneStepOfYourHeavyWork();
}


The modern way of doing the same thing is to divide the application into two independant parts (threads) -- one of them is taking care of events, and the other performs your work without caring about the other thread:

Source code

1
2
3
4
5
6
7
8
9
// thread one ("GUI thread"):
while(1){
    if(event queue not empty) processEventFromQueue();
}

//thread two ("Worker thread"):
while(1){
    performOneStepOfYourHeavyWork();
}


This way the operating system (or rather the threading scheduler to be precise) makes sure both threads get executed when the CPU hasn't got anything else to do (more or less).

If you don't know what it all means, then you probably don't need it at all.

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

5

Monday, May 9th 2005, 2:58pm

RE: use timer->start(0,FALSE) to provide snappy user interface?

It means that nowadays you do the heavy work in a separate thread and you don't have to remember about processing events from time to time.

Futhermore, if you have more than one processor, that worker thread might work in parallel to the GUI thread. And it looks like in the near future PCs will turn into SMPs, thanks to multicore CPUs.