[Qt-interest] QThread vs QTimer for polling
Martin Hofius
Martin at hofius-online.com
Mon Mar 1 12:25:00 CET 2010
Am Samstag, 27. Februar 2010 schrieb Mandeep Sandhu:
> Hi All,
>
> I'm using Qt on an embedded platform.
>
> My application is required to poll a particular h/w component for
> status changes/monitoring. Basically my application wants to get the
> status of a certain commands given to the h/w (these commands don't
> have immediate effect and hence the need for polling). Polling must be
> done till the time the requested status is achieved OR the maximum
> number of retires have been exceeded. Once the app gets the status, no
> more polling is needed till it issues another command.
>
Hi,
> I can think of 2 ways of achieving this:
first question: does the 3rd party lib provide only non blocking access?
If not then...
use QThread, send your command and make a blocking access in your thread. So
the thread will do nothing (and cost nothing except memory) until the result
comes from your h/w - the you can send a signal to your main app or just
send the next command in your thread. I think this is the best case.
If this lib only provides non blocking access, using a thread will always cost
more cpu cycles by the advance of sligtly more accuracy compared to a main
event loop timer.
Martin
More information about the Qt-interest-old
mailing list