-1

I am trying to get a basic program implementing QtConcurrent to work. Found a lot of sites with similar problems, but none of their solutions worked for me so far.

My code:

void Setup::addOne(int &i)
{
    ++i;
}

void Setup::Test()
{
    QList<int> list;
    list.append(1);
    QtConcurrent::map(list, &Setup::addOne);
}

Trying to build it shows the following error:

C2064: term does not evaluate to a function taking 1 arguments

The error refers to the following lines in qtconcurrentmapkernel.h:

bool runIteration(Iterator it, int, void *)
{
    map(*it);
    return false;
}

I am working with Qt5. Thank you for your help.

Ryan
  • 125
  • 1
  • 7

1 Answers1

5

Non-static member functions actually have a hidden argument, a pointer to the object which becomes this inside the function.

Unless you need to access member variables or call other member functions, I suggest you make the addOne function static.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 1
    if you *do* need to access members, wrap the method up like `[this](int &i){ addOne(i); }` – Caleth May 30 '17 at 09:40