Results 1 to 4 of 4

Thread: How to use QFutureInterface?

  1. #1
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to use QFutureInterface?

    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:
    Qt Code:
    1. static void find_helper(QFutureInterface<Usage> &future,
    2. const CppModelManagerInterface::WorkingCopy workingCopy,
    3. const LookupContext context,
    4. CppFindReferences *findRefs,
    5. Symbol *symbol){....}
    6. const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
    7. QFuture<Usage> result;
    8. result = QtConcurrent::run(&find_helper, workingCopy,
    9. parameters.context, this, parameters.symbol);
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QFutureInterface?

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QFutureInterface?

    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();
    }

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QFutureInterface?

    Quote Originally Posted by Michael_BJFU View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.