How to correctly Connect from qthreadpool
-
Hello,
I develop a small program, where i add in a Loop multiple small Tasks to a Threads.
If the Work ist done i want to add a Line to a qlist.
But how did i correctly Connect that Tasks to emit the Signal? Or is there a way to Check from qthreadpool when the Task ist finished?Greetz from germany
-
Hi,
Do you mean from your QRunnable subclass ?
-
Hy,
thats what i mean.i have implemented a QRunnable to do that work.
Then i loop through a list were the params in, create an object, connect the signal and slot, and start the work with pool->start().But all i get is "Function recv() failed" on console but no entrie in my list.
Is that correct? Or shall i implement an own kind of threadpool?regards,
-
Since you have a list of parameters that you iterate, why not use QtConcurrent::map and QFutureWatcher ?
You'll have the progress indication for free.
-
I know Threadpools from python and thought it works the same way.
But ok i will give that a shot.QImage scaled(const QImage &image)
{
return image.scaled(100, 100);
}QList<QImage> images = ...;
QFuture<QImage> thumbnails = QtConcurrent::mapped(images, scaled);like that?
Thx
-
Yes, adding a QFutureWatcher in the mix.
-
@PXLFuSSeL You get the result from QFuture and then update the GUI. Using QFutureWatcher (as @SGaist suggested) you also get notification when a job is finished and then use QFuture to get the result.
-
As already hinted twice, QFutureWatcher is your friend.