Concurrent map equivalent
Solved
General and Desktop
-
struct NameHelper { NameHelper(const QString &extra) : _extra(extra) { } typedef QString result_type; QString operator()(const QString &name) { for(int i = 0; i < 999999; ++i) { qDebug() << "block"; } return QString("Hello %1 %2").arg(name).arg(_extra); } QString _extra; }; QStringList names = { "john", "jane" }; QString extra = "doe"; QFuture<QString> example = QtConcurrent::mapped(names, NameHelper(extra));
-
operator()
will be executed in another thread, it will not block the GUI thread, it will not return until completed (of course) -
@Defohin said in Concurrent map equivalent:
But why is it not appearing the window If it's running in another thread?
WOW! we are taking this on a whole new level here! you need a QFutureWatcher on the QFuture and a slot connected to the
resultReadyAt
signal to display the results in the GUI -
- If you want to stop the calculation when the widget is closed reimplement the closeEvent and call cancel on the QFuture
- If you want to stop the calculation when the widget is destroyed reimplement the destructor and call cancel on the QFuture