Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use QtConcurrent::run

How to use QtConcurrent::run

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mapple
    wrote on last edited by
    #1

    I have a class:

    @class MyThread : public QThread
    {
    Q_OBJECT
    public:
    MyThread (QObject *parent = 0);

    signals:
    void nextCalculationReady(const double value) const;

    protected:
    void run();

    private:
    void asyncFunction(const double x) const;
    };

    MyThread::MyThread(QObject *parent) :
    QThread(parent)
    { }

    void MyThread::run()
    {
    double x = 0.0;
    //do something
    QtConcurrent::run(this, &MyThread::asyncFunction, x); // QFuture object is not needed. It doesn't work
    // QtConcurrent::run(this, &MyThread::asyncFunction, x); // It doesn't work
    // QtConcurrent::run((MyThread
    )this, &MyThread::asyncFunction, x); // It doesn't work
    }

    void MyThread::asyncFunction(const double x) const
    {
    //do something
    emit nextCalculationReady(x);
    }@

    I want run asyncFunction asynchronously in another thread. But when I write *this or simply this in a QtConcurrent::run - function call I get compiler issue.

    I've read the documentation and maybe I've missed something.
    How to use QtConcurrent::run with calling a member function of class?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mapple
      wrote on last edited by
      #2

      If I use @QtConcurrent::run(*this, &MyThread::asyncFunction, x);@

      Compiler error:

      c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore\qthread.h:137: error: C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'

      If I use @QtConcurrent::run(this, &MyThread::asyncFunction, x);@

      Compiler error:
      c:\qtsdk\desktop\qt\4.8.0\msvc2010\include\qtcore\qtconcurrentrun.h:123: error: C2064: term does not evaluate to a function taking 2 arguments

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved