PDA

View Full Version : which one has finished with QFutrueWatcher



wookoon
27th July 2010, 12:11
Hi , all

I need compute some different data at one time ,so I use the QtConcurrent:run to

compute the data , and use QFutrueWatcher to monitor the computing state.

Here is the a section of the code.


**.h

QVector<QFuture<void> *> ftVec;
QVector<QFutureWatcher<void> *> ftwVec;


**.cpp

//begin a new computation.
ftVec << new QFuture<void>;
ftwVec << new QFutureWatcher<void>;

connect(ftwVec[num], SIGNAL(finished()),this, SLOT(getresultFunction()));

*ftVec[num] = QtConcurrent::run(this,&MainWindow::computeFuntion);
ftwVec[num]->setFuture(*ftVec[num]);
num++;



I want know which watcher is finished when it execute the function getresultFunction.

Give me some suggestions. Thanks..!

tbscope
27th July 2010, 12:23
The most correct way to do this is to use a QSignalMapper

wysota
27th July 2010, 12:41
You are probably overcomplicating things. Try this approach:


void MainWindow::computeFunction(const MyArg &arg) {
doSomethingWith(arg);
} // static

QList<MyArg> computations;
fillDataInto(computations);
QFutureWatcher watcher;
connect(&watcher, SIGNAL(resultReadyAt(int)), ...);
QFuture<void> future = QtConcurrent::map(computations, MainWindow::computeFunction);
watcher.setFuture(future);

You'll get much cleaner design.