PDA

View Full Version : How to use QFutureInterface?



Michael_BJFU
23rd July 2012, 08:15
I want to use QFutureInterface, but its doc is not provided in Qt Assistant. So I have to use the Qt Creator source to have a look at how it is used.
The codes look like these:


static void find_helper(QFutureInterface<Usage> &future,
const CppModelManagerInterface::WorkingCopy workingCopy,
const LookupContext context,
CppFindReferences *findRefs,
Symbol *symbol){....}
const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
QFuture<Usage> result;
result = QtConcurrent::run(&find_helper, workingCopy,
parameters.context, this, parameters.symbol);

Note that the first parameter is not provided by the caller!!!Just like the pointer "this". Why ? When I write a code snippet like that, it complied error.
Can Anyone help me ? Thanks.

wysota
23rd July 2012, 08:31
Download Qt sourcecode and see how QtConcurrent::run() is really implemented. I don't have it before my eyes right now but I'm guessing it will create a QFutureInterface instance and call find_helper on it.

Why do you want to use QFutureInterface instead of QFuture anyway?

Michael_BJFU
23rd July 2012, 09:23
Thanks for your reply. Normally, the task using QFutureInterface::run()can not be paused or setProgressValue(). But if the QFutureInterface is provided, I can use setProgressValue() or the other function. What confused me most is that how the first parameter can be ignored ? What kind of mechanism is it?
This is the source code of the Qt.
template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2>
QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2)
{
return (new QT_TYPENAME SelectStoredMemberFunctionPointerCall2<T, Class, Param1, Arg1, Param2, Arg2>::type(fn, object, arg1, arg2))->start();
}

wysota
23rd July 2012, 14:09
Thanks for your reply. Normally, the task using QFutureInterface::run()can not be paused or setProgressValue(). But if the QFutureInterface is provided, I can use setProgressValue() or the other function.
I don't understand what you mean.


What confused me most is that how the first parameter can be ignored ? What kind of mechanism is it?
This is the source code of the Qt.
template <typename T, typename Class, typename Param1, typename Arg1, typename Param2, typename Arg2>
QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2)
{
return (new QT_TYPENAME SelectStoredMemberFunctionPointerCall2<T, Class, Param1, Arg1, Param2, Arg2>::type(fn, object, arg1, arg2))->start();
}

There are multiple run() implementations, that's just one of them and definitely not the one used by the code you quoted earlier.