Hello. There is a pool of threads, for example, there are 10 of them. How to make it so that on completion of each of the threads there is an increase in the ProgressBar? For example, there are 10 elements, for each element along the stream, a total of 100/10 each completion of the stream + 10% to progressBar. How to make such a ProgressBar? The test case code is below:
Start of everything:
void Calculate::start() { QVector<int> elements; for (int i = 0; i < 100; i++) { elements.append(i); } QVector<int> KA; for (int i = 0; i < 10; i++) { KA.append(i); } for (int i = 0; i < KA.size(); i++) { Worker * worker = new Worker(i); worker->setAutoDelete(false); worker->setElements(&elements,elements.size()); QThreadPool *threadPool = QThreadPool::globalInstance(); threadPool->setMaxThreadCount(KA.size()); threadPool->start(worker); } } Worker.h
#ifndef WORKER_H #define WORKER_H #include <QObject> #include <QRunnable> class Worker : public QObject, public QRunnable { Q_OBJECT public: Worker(int _indexKA); ~Worker(); void setElements(QVector<int> *_elements, int size) { elements = _elements; sizeElements = size; } virtual void run(); signals: private: int indexKA; QVector<int> *elements; int sizeElements; }; #endif // WORKER_H Worker.cpp
#include "worker.h" #include <QDebug> Worker::Worker(int _indexKA) { indexKA = _indexKA; } Worker::~Worker() { } void Worker::run() { qDebug() << "START"; int summ = 0; for (int i = 0; i < sizeElements; i++) { summ = indexKA + i; qDebug() << summ; } qDebug() << summ; // здесь как то уведомить поток о завершении и передать 10% в прогресс бар }