开发者

Start and run a class member function in background, in QT/C++

Once 开发者_如何学运维a minute I want to run a task, not blocking other GUI functions. I heared somthing about QConcurent::run ...

Or should I use signals and slots?


Use QConcurrent it sounds like what you need. And you can use QFutureWatcher to get signals when it's done (which uses signals and slots)


There is a world of differences between the two options you are discussing.

My experiences have been -

  1. For functions that don't take very long to execute and the GUI thread is not very busy, use signals and slots. It is the easiest.
  2. If your task is longer running, then you can use QConcurrent/QFutureWather as suggested by SB.
  3. You can also look at using QThread or QThreadPool.

You have 3 at least choices if you need to multithread (using just Qt). Each approach is somewhat different in how they work and what their overhead costs are. The real choice needs to be made on how you are using threading in the rest of your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜