views:

143

answers:

2

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?

+2  A: 

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)

SB
what does it do exactly?
Regof
Read the docs! Basically executes a task in another thread obtained from a threadpool.
SB
sounds great, could you show me an example?
Regof
It appears his answer was a more verbose version of mine. But I'll try to be more polite in future responses. Thanks for the input. I hope you do try to figure out what the code is doing rather than cutting and pasting. The link I gave you in the comment should give you a solid start.
SB
No seriously - you don't even know me, but you tell something about copy/paste. I am new to QT and I enjoy talking to the people who are experienced in QT. That's it :-) Help and let help
Regof
that is the purpose of StackOverflow right? Prove me otherwise...For the rest I ment no offence myself
Regof
and in all other respects your answer is valuable, including the link to the example
Regof
Sorry for being mean - I may have been grumpy at the time. I've deleted the unnecessary comment, but here is the example again: http://doc.trolltech.com/4.4/qtconcurrent-runfunction.html
SB
+2  A: 

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.

photo_tom
Based on his comments, it seemed he didn't want to take a chance on blocking the GUI, so I recommended the QConcurrent - plus they're simple to kick off every minute like he wants to. It grabs a thread from a QThreadPool setup by the framework.
SB
Thanks for comment. I wasn't aware that QConcurrent used QThreadPool.
photo_tom
photo_tom, thanks for the answer, but SB's answer is more complete and it has the example I needed, so I makt SB's answer as the answer to this question and I vote for your answer too
Regof