Wednesday 15 May 2013

c++ - QThreadPool example -


I'm looking for a brief example on the use of QThreadPool . Here's how I have used it:

  Koothhidpool * thread_pull = QuthHadPull :: Global instances (); MyThread * thread = new MyThread (); Thread_pool-> Start (thread); Class MyThread: Public QRunnable {Public: MyThread (); ~ MyThread (); Running zero (); }; Zero MyThread :: Run () {qDebug () & lt; & Lt; "MyThread"; }   

What is the correct practice? PS: I wait in context, when should I call waitForDone ?

This is almost right with one exception QRunnable is not a thread, And you should not call your class MyThread . MyRunnable or MyTask is more correct

Note that your code is almost like an example. Documentation is the best source of short instances.

You should call waitForDone when you want to wait until all runnabels are processed. It depends on the architecture of your app. Usually this happens when you create and start all QRunnable s and want to use your results.

No comments:

Post a Comment