Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QRunnable - how to use it, examples

Could point at some code using QRunnable as an alternative to QtConcurrent: I can't find any QRunnable example in Qtdoc.

Did you ever try QRunnable AND QtConcurrent for same application, and could you comment on the compared performance?

like image 532
kiriloff Avatar asked Apr 12 '12 15:04

kiriloff


1 Answers

QRunnable is an interface. So rather than looking for "a QRunnable example" it would be better to look for (for instance) "a QThreadPool example", such as:

http://doc.qt.io/qt-4.8/thread-basics.html#example-1-using-the-thread-pool

If you read further on that page, it mentions the real value in QtConcurrent is when you are doing something similar to applying an STL algorithm to an STL container. Using a thread pool with QRunnable is better for when you just have a bunch of fairly unrelated tasks to perform.

QtConcurrent is built on top of QThreadPool. It's notationally convenient and keeps you from having to write the patterns yourself, but is not going to intrinsically speed you up over what you could hand code. But...thinking in terms of QtConcurrent patterns (such as MapReduce) may help you see opportunities for parallelism you wouldn't otherwise think of, and writing less code means it's easier to try alternative approaches and compare their performance.

like image 109
HostileFork says dont trust SE Avatar answered Sep 29 '22 13:09

HostileFork says dont trust SE