"...back to the future ..."
-
When I used this call
// Start the computation. QFuture<int> future = QtConcurrent::run(...); watcher.setFuture(future);
"future" contained # of devices detected by the function run by QtConcurrent.
How do I retrieve this value (int) returned by the function when I "bypass " QTFuturre using this callwatcher->setFuture(QtConcurrent::run( std::bind( hci_inquiry, dev_id, len, max_rsp, lap, , &ii, flags) ));
QTFutureWatcher have access to "indexes" but I really do not get what they are.
Now "watcher" is defined this way
watcher = new QFutureWatcher<int>;
so all these are templates and I am lost using them correctly.
I would appreciated reply with code. -
@AnneRanch call result() the returned type is the same as the QFuture you have set.
E.g:
if you set a QFuture ofQFuture<QPair<quint64, double>>
, then result will return aQPair<quint64, double>
-
This was demonstrated in the example provided to another of your threads on this same topic area
-
@J-Hilk said in "...back to the future ...":
@AnneRanch call result() the returned type is the same as the QFuture you have set.
E.g:
if you set a QFuture ofQFuture<QPair<quint64, double>>
, then result will return aQPair<quint64, double>
OK, that is how return TYPE is specified in QTFuture.
How is it specified in QTFutureWatcher ?I am getting watcher -> return -1 which is obviously an error coming from
the hci_inquiry . Which is OK and fixable. -
The watcher is templated on the return type of the future it watches, so you can retrieve the result simply like this:
int result = watcher->result();
-
@AnneRanch said in "...back to the future ...":
OK, that is how return TYPE is specified in QTFuture.
How is it specified in QTFutureWatcher ?I now realise I should have been more explicit: I highlighted the new part in bold:
E.g:
if you set a QFuture of QFuture<QPair<quint64, double>>, then calling QFutureWatcher:: result() will return a QPair<quint64, double> ** -
@AnneRanch said in "...back to the future ...":
OK, that is how return TYPE is specified in QTFuture.
How is it specified in QTFutureWatcher ?QFutureWatcher gets the type from QFuture. Using C++ templates.