#include <QCoreApplication>
#include <QtConcurrent>
int do_map(int value)
{
qInfo() << "Do stuff: " << value;
int num = value * 10;
return num;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QList<int> values;
for(int i = 0; i < 9; i++)
{
values << i;
}
qInfo() << "Starting...";
QList<int> updated = QtConcurrent::blockingMapped(values,&do_map);
qInfo() << "Finished";
qInfo() << updated;
return a.exec();
}
#include <QCoreApplication>
#include <QtConcurrent>
#include <QThread>
#include <QThreadPool>
void loop()
{
for (int i = 0; i < 10;i++)
{
qInfo() << "Loop" << i << " on: " << QThread::currentThread();
}
}
void test()
{
qInfo() << "Test on: " << QThread::currentThread();
loop();
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QThread::currentThread()->setObjectName("Main");
QThreadPool pool;
QFuture<void> future = QtConcurrent::run(&pool,test);
qInfo() << "Main on: " << QThread::currentThread();
return a.exec();
}
#include <QCoreApplication>
#include <QtConcurrent>
#include <QThread>
#include <QFuture>
void test(QString name, int max)
{
for (int i = 0;i < max;i++)
{
qInfo() << name << i << QThread::currentThread();
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString name = "name";
QFuture<void> future = QtConcurrent::run(test,name,5);
qInfo() << "Do stuff here";
//Wait for finished
future.waitForFinished(); //Block
qInfo() << "Done";
return a.exec();
}