Regof
Regof

Reputation: 2857

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?

Upvotes: 0

Views: 1941

Answers (2)

photo_tom
photo_tom

Reputation: 7342

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.

Upvotes: 2

NG.
NG.

Reputation: 22914

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)

Upvotes: 2

Related Questions