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

Qt-interest Archive, December 2006
Idle processing on Windows with Qt and Quicktime


Message 1 in thread

Hey folks,
I am new to Qt as well as QT programming.  In quicktime you have to
allocate time to task quicktime to render the movie file you are
playing.  A good way to do this is to call the MCIdle (quicktime movie
control function) function in the event loop during an "idle" event.

I have seen a number of posts recommending the use of a timer set for
"0", upon the wakeup event, call your idle processing function.   
- The first problem is when a modal file dialog box pops up, it stops
all timer events.  - Second, when I do use a "zero second timer", my CPU
utilization goes up to 50% (I am running a P4 3GHz with hyperthreading),
which is unnacceptable.  And oh by the way, I even tried this without
making any function calls.  50% was just adding the 0 second timer and
calling an empty function. 
- Third, it kinda seems like a hack.

I searched a lot all over the place, and I can't seem to find a method
to attach idle processing to a widget.  

Any help would be appreciated.  I am looking for how to setup and event
loop, and more specifically catching the "idle" event in that event
loop.

thanks

--
 [ signature omitted ] 

Message 2 in thread

Am Mittwoch, 6. Dezember 2006 17:23 schrieb Duen, Eric:
> I have seen a number of posts recommending the use of a timer set for
> "0", upon the wakeup event, call your idle processing function.
> - The first problem is when a modal file dialog box pops up, it stops
> all timer events.  - Second, when I do use a "zero second timer", my CPU
> utilization goes up to 50% (I am running a P4 3GHz with hyperthreading),
> which is unnacceptable.  And oh by the way, I even tried this without
> making any function calls.  50% was just adding the 0 second timer and
> calling an empty function.
> - Third, it kinda seems like a hack.
You could subclass QThread, set it's priority to QThread::IdlePriority and 
either do your stuff directly inside run() or by starting an event-loop in 
your thread using exec(). With the help of this event-loop you can use 
zero-timers which only should fire when idle.

toby

Attachment:

Attachment: pgpK06DOx0R2X.pgp
Description: PGP signature


Message 3 in thread

Try to connect to

http://doc.trolltech.com/4.2/qabstracteventdispatcher.html#aboutToBlock

This should only fire if there are no more events in the queue, i.e. if 
the application is about to go idle.

Volker

"Duen, Eric " <Eric_Duen@xxxxxxxx> wrote in message 
news:FBBBA62F7E8B9B458A85BEB60C175874011F44CB@xxxxxxxxxxxxxxxxxxxxxxxx
Hey folks,
I am new to Qt as well as QT programming.  In quicktime you have to
allocate time to task quicktime to render the movie file you are
playing.  A good way to do this is to call the MCIdle (quicktime movie
control function) function in the event loop during an "idle" event.

I have seen a number of posts recommending the use of a timer set for
"0", upon the wakeup event, call your idle processing function.
- The first problem is when a modal file dialog box pops up, it stops
all timer events.  - Second, when I do use a "zero second timer", my CPU
utilization goes up to 50% (I am running a P4 3GHz with hyperthreading),
which is unnacceptable.  And oh by the way, I even tried this without
making any function calls.  50% was just adding the 0 second timer and
calling an empty function.
- Third, it kinda seems like a hack.

I searched a lot all over the place, and I can't seem to find a method
to attach idle processing to a widget.

Any help would be appreciated.  I am looking for how to setup and event
loop, and more specifically catching the "idle" event in that event
loop.

thanks

--
 [ signature omitted ] 

Message 4 in thread

Am Mittwoch, 6. Dezember 2006 18:18 schrieb Volker Hilsheimer:
> Try to connect to
>
> http://doc.trolltech.com/4.2/qabstracteventdispatcher.html#aboutToBlock
>
> This should only fire if there are no more events in the queue, i.e. if
> the application is about to go idle.
In this document I can't see anything that has something to do with 
idle-processing or so ???  This signal is emitted, before the event loop is 
going to execute a function which could block...

toby

Attachment:

Attachment: pgpM6SEgBo9Et.pgp
Description: PGP signature


Message 5 in thread

"Tobias Doerffel" <tobias.doerffel@xxxxxxxxx> wrote in message 
news:200612061821.44275.tobias.doerffel@xxxxxxxxxxxx
> Am Mittwoch, 6. Dezember 2006 18:18 schrieb Volker Hilsheimer:
> > Try to connect to
> >
> > http://doc.trolltech.com/4.2/qabstracteventdispatcher.html#aboutToBlock
> >
> > This should only fire if there are no more events in the queue, i.e. 
> > if
> > the application is about to go idle.
>
> In this document I can't see anything that has something to do with
> idle-processing or so ???  This signal is emitted, before the event loop 
> is
> going to execute a function which could block...

Yes, and if the functions called could block, then this usually implies 
that there are no more events.


Have you tried it?

Volker


--
 [ signature omitted ] 

Message 6 in thread

Am Mittwoch, 6. Dezember 2006 17:23 schrieb Duen, Eric:
> I have seen a number of posts recommending the use of a timer set for
> "0", upon the wakeup event, call your idle processing function.
> - The first problem is when a modal file dialog box pops up, it stops
> all timer events.  - Second, when I do use a "zero second timer", my CPU
> utilization goes up to 50% (I am running a P4 3GHz with hyperthreading),
> which is unnacceptable.  And oh by the way, I even tried this without
> making any function calls.  50% was just adding the 0 second timer and
> calling an empty function.
Well what did you exspect?! You cpu is busy calling that empty function 
whenever it is idle. So it's never idle :-)
You will see a 100% load on a no hyperthreaded cpu.

--
 [ signature omitted ] 

Message 7 in thread

I read about the function, and I would have to say my understanding of
QT and how things work is rather limited.  I didn't quite know how to
use it.  Currently I am overloading the TimerEvent function and setting
a timer for 60ms, and then I do my "idle processing". CPU utilization
went to sub 3% (as compared to 50% with a timer of 0).  So for now that
is OK, but I still don't like the solution.

Hopefully I can better understand the event system, and can use that in
the future.  Any tips on how to better understand it?

thanks

eric


-----Original Message-----
From: Volker Hilsheimer [mailto:unwatched@xxxxxxx] 
Sent: Thursday, December 07, 2006 4:26 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Idle processing on Windows with Qt and Quicktime

"Tobias Doerffel" <tobias.doerffel@xxxxxxxxx> wrote in message
news:200612061821.44275.tobias.doerffel@xxxxxxxxxxxx
> Am Mittwoch, 6. Dezember 2006 18:18 schrieb Volker Hilsheimer:
> > Try to connect to
> >
> > http://doc.trolltech.com/4.2/qabstracteventdispatcher.html#aboutToBl
> > ock
> >
> > This should only fire if there are no more events in the queue, i.e.

> > if
> > the application is about to go idle.
>
> In this document I can't see anything that has something to do with 
> idle-processing or so ???  This signal is emitted, before the event 
> loop is going to execute a function which could block...

Yes, and if the functions called could block, then this usually implies
that there are no more events.


Have you tried it?

Volker


--
 [ signature omitted ] 

Message 8 in thread

Am Donnerstag, 7. Dezember 2006 14:37 schrieb Duen, Eric:
> I read about the function, and I would have to say my understanding of
> QT and how things work is rather limited.  I didn't quite know how to
> use it.  Currently I am overloading the TimerEvent function and setting
> a timer for 60ms, and then I do my "idle processing". CPU utilization
> went to sub 3% (as compared to 50% with a timer of 0).  So for now that
> is OK, but I still don't like the solution.
Where's the problem with creating an own thread? Or do you want to do 
GUI-things while idle?

toby

Attachment:

Attachment: pgpEanr4D9KLl.pgp
Description: PGP signature


Message 9 in thread

Actually I tried the thread thing first.  But I misread your email and
created an IdlePriority thread with a timer in it.  Then I find out I
can't use a timer in a non-main thread unless there is an event loop.  I
would have liked to do that, but I couldn't easily figure out how to do
the event loop (any suggestion).  

I also tried doing the "idle processing" in the run function of the
thread, but I went from 50% cpu utilization (timer.start(0)) to
90%...d'oh!

I am very new (1 week) to Qt and not much more experience doing Windows
GUI work, so doing stuff like event loops is a bit foreign to me.  I
would love to learn how to do that, but for the time being I have to get
something running.  I will probably revisit the topic in the near future
though, but if you have suggestion or pointers on how to do an event
loop, that would be helpful.

thanks a bunch

eric

-----Original Message-----
From: Tobias Doerffel [mailto:tobias.doerffel@xxxxxxxxx] 
Sent: Thursday, December 07, 2006 10:36 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Idle processing on Windows with Qt and Quicktime

Am Donnerstag, 7. Dezember 2006 14:37 schrieb Duen, Eric:
> I read about the function, and I would have to say my understanding of

> QT and how things work is rather limited.  I didn't quite know how to 
> use it.  Currently I am overloading the TimerEvent function and 
> setting a timer for 60ms, and then I do my "idle processing". CPU 
> utilization went to sub 3% (as compared to 50% with a timer of 0).  So

> for now that is OK, but I still don't like the solution.
Where's the problem with creating an own thread? Or do you want to do
GUI-things while idle?

toby

--
 [ signature omitted ] 

Message 10 in thread

Duen, Eric wrote:
> Actually I tried the thread thing first.  But I misread your email and
> created an IdlePriority thread with a timer in it.  Then I find out I
> can't use a timer in a non-main thread unless there is an event loop.  I
> would have liked to do that, but I couldn't easily figure out how to do
> the event loop (any suggestion).  
>
> I also tried doing the "idle processing" in the run function of the
> thread, but I went from 50% cpu utilization (timer.start(0)) to
> 90%...d'oh!
>
> I am very new (1 week) to Qt and not much more experience doing Windows
> GUI work, so doing stuff like event loops is a bit foreign to me.  I
> would love to learn how to do that, but for the time being I have to get
> something running.  I will probably revisit the topic in the near future
> though, but if you have suggestion or pointers on how to do an event
> loop, that would be helpful.
>
> thanks a bunch
>
> eric
>
> -----Original Message-----
> From: Tobias Doerffel [mailto:tobias.doerffel@xxxxxxxxx] 
> Sent: Thursday, December 07, 2006 10:36 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Idle processing on Windows with Qt and Quicktime
>
> Am Donnerstag, 7. Dezember 2006 14:37 schrieb Duen, Eric:
>   
>> I read about the function, and I would have to say my understanding of
>>     
>
>   
>> QT and how things work is rather limited.  I didn't quite know how to 
>> use it.  Currently I am overloading the TimerEvent function and 
>> setting a timer for 60ms, and then I do my "idle processing". CPU 
>> utilization went to sub 3% (as compared to 50% with a timer of 0).  So
>>     
>
>   
>> for now that is OK, but I still don't like the solution.
>>     
> Where's the problem with creating an own thread? Or do you want to do
> GUI-things while idle?
>
> toby
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>   
Eric,

I think I know what you want, but you have to expect high CPU 
utilization during idle processing because by definition processing == 
CPU usage.  I think you want to do something like a "background 
spreadsheet recalc" type thing.  Here is my suggestion:

You need to have a function that works incrementally and a single shot 
timer. Here is a some psuedo code:

void Thinggy::slotAsyncRecalc()
{
    // Do a reasonable amount of work
    // Dequeue cells, save other states, etc
   
    if( m_dirtyCells.size() > 0)
    {
        QTimer::singleShot(0, this, slotAsyncRecalc());
       // 0 could be adjusted to use less CPU
    }
   
    //We are out. There are no more dirty cells to recalc
    // No more processing until the user hits the button or whatever again!
}


Good Luck,
--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard