Results 1 to 4 of 4

Thread: QtConcurrent::run Help(SOLVED)

  1. #1

    Default QtConcurrent::run Help(SOLVED)

    This is probaly more of a C++ question than a Qt question. But nevertheless it involves the QtConcurrent::run function.

    My question is, what is the proper way to pass a function into QtConcurrent::run? I want to pass a member function that is inherited specifically, but no matter what I do it throws a long list of errors saying im not using the function correctly. Also the function has parameter, one of which is a pointer, is this okay?

    I've read the documentation and maybe I've missed something. But it doesn't seem to be very detailed on what is allowed and not and maybe I should just know.
    If anyone can give me any insight thanks.
    Last edited by AwDogsgo2Heaven; 9th July 2009 at 03:26. Reason: question was answered

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtConcurrent::run Help

    can you show the code? may be its the case of missing & or class qualifier

  3. #3

    Default Re: QtConcurrent::run Help

    I dont have the code on me. But here is a pretty much same example:

    I tried doing this -

    QFuture<void> future = QtConcurrent::run(&Scope::function, parameter);

    The scope was of the inherited class and the parameter was a pointer to an object.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtConcurrent::run Help

    i think the docs read that you have to pass an object or the pointer to call a member function...

    Additional API Features
    Using Member Functions
    QtConcurrent::run() also accepts pointers to member functions. The first argument must be either a const reference or a pointer to an instance of the class. Passing by const reference is useful when calling const member functions; passing by pointer is useful for calling non-const member functions that modify the instance.
    For example, calling QString::split() (a const member function) in a separate thread is done like this:
    // call 'QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const' in a separate thread
    QString string = ...;
    QFuture<QStringList> future = QtConcurrent::run(string, &QString::split, QString(", "), QString::KeepEmptyParts, Qt::CaseSensitive);
    ...
    QStringList result = future.result();
    Calling a non-const member function is done like this:
    // call 'void QImage::invertPixels(InvertMode mode)' in a separate thread
    QImage image = ...;
    QFuture<void> future = QtConcurrent::run(image, &QImage::invertPixels, QImage::InvertRgba);
    ...
    future.waitForFinished();
    // At this point, the pixels in 'image' have been inverted

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.