[Interest] Heavily Commented Example: Simple Single Frontend with Two Backends

Till Oliver Knoll till.oliver.knoll at gmail.com
Mon Oct 22 08:50:14 CEST 2012


Am 22.10.2012 um 07:21 schrieb d3fault <d3faultdotxbe at gmail.com>:

>> ...If you only need to read from the serial port periodically, you can set your backend up like I did for backend2 in the exampe... which also uses a timer.
>> 
If that implies getting rid of a 2nd "polling thread" entirely then that's something I would have also suggested.

Using a simple QTimer which fires periodically, say, every 50 ms, has less overhead than waking up a thread with the same periodicity. Plus it is simpler, as no data has to protected my mutexes (=additional overhead).

If on the other hand data is incoming infrequently ("you would fire many times the timer in vain") AND you have some sort of (hardware interrupt) signal that new data is present, only then waking up a thread and process the data asynchronously is more performant.

But if the data processing itself is time-consuming and blocking the gui in a significant way, and you /really/ need to poll ("no hardware signal telling you there's data") then you could combine a QTimer and thread: poll with a timer ("cheap"), and only IF there is data wake up the "data process" thread and let it handle the data as long as there is data incoming (mute the timer in the meantime!). As soon as no data is incoming anymore, start polling with the timer and put the thread to sleep again.

Cheers,
  Oliver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121022/b79dd127/attachment.html>


More information about the Interest mailing list