void MyClass::calculationFunc(const QVector& list){ for(int i = 0; i < list.size(); i++) { my work }}
for(int n = 0; n < 3; n++){ QThread* thread = new QThread(this); ......здесь не знаю что писать}
class MyClass{public: MyClass() { } void hello(QString name, long long value) { int xx =_intValue; long long x = value;//2111111111; while(x) x--; qDebug() << "Hello" << name << "from" << QThread::currentThread(); }private: int _intValue = 4;};int main(int argc, char *argv[]){ QApplication a(argc, argv); MyClass class1; QFuture<void> f1 = QtConcurrent::run(&class1,&MyClass::hello, QString("Alice"), 2111111111); QFuture<void> f2 = QtConcurrent::run(&class1,&MyClass::hello, QString("Bob"), 3111111111); f1.waitForFinished(); f2.waitForFinished();return 0;}
int count_thread = QThread::idealThreadCount()-1; QFuture <void> f; for(int i = 0; i < count_thread; i++) { f = QtConcurrent::run(_managerObj,&iManager::calcRebate, i); } f.waitForFinished();
int count_thread = QThread::idealThreadCount()-1; std::vector<QFuture<void>> futures; futures.reserve(count_thread); for(int i = 0; i < count_thread; i++) { futures.push_back(QtConcurrent::run(_managerObj,&iManager::calcRebate, i)); } for (auto &f: futures) // const auto? f.waitForFinished();
int count_thread = QThread::idealThreadCount()-1; std::vector<i> tasks; tasks.reserve(count_thread); for(int i = 0; i < count_thread; i++) { tasks.push_back(i); } const auto future = QtConcurrent::map([&_managerObj](int i){ _managerObj->calcRebate(i); return i; }, tasks); future.waitForFinished();
QVector<QString> listStr; QVector<long long> listLong; auto future = QtConcurrent::map([&classObj](QString str,long long l){ classObj.incrCalc(str,l); return str; }, listStr,listLong);