0

I'm trying to run non-static member function in the other thread. If I go:

void *(PortManager::*innerAskPtr)() = &this->innerAsk;
QFuture<void> f = QtConcurrent::run(innerAskPtr);

it prompts that

ISO C++ forbids taking the adress of an unqualified or parenthesized non-static member function to form a pointer to member function.

but if I delete this extra reference symbol:

void *(PortManager::*innerAskPtr)() = this->innerAsk;
QFuture<void> f = QtConcurrent::run(innerAskPtr);

it goes that it

cannot convert 'PortManager::innerAsk' from type 'void (PortManager::)()' to type 'void* (PortManager::*)()`

What to add on the right side to get these extra stars (*) on the left?

But still, even if I would get there, there is always another error; about the run(T(*)()):

no matching function for call to 'run(void* (PortManager::*&)())

it's so over my head to understand how this reference got there...

smsware
  • 429
  • 1
  • 13
  • 41
  • @MattMcNabb can it be just non-member function which will take pointer to object on which it will operate, as an argument? – smsware Jun 04 '14 at 02:52

1 Answers1

2

The documentation for QtConcurrent::run seems to explain all this.

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.

There are code examples immediately following this text.

In your code:

void *(PortManager::*innerAskPtr)() = this->innerAsk;
QFuture<void> f = QtConcurrent::run(innerAskPtr);

the error message indicates that this->innerAsk returns void, but you are trying to assign it to a pointer-to-member-function returning void *. You probably meant:

void (PortManager::*innerAskPtr)() = &PortManager::innerAsk;

but you don't need to do this in order to call QtConcurrent::run, as the code examples show you can just write:

QtConcurrent::run( this, &PortManager::innerAsk );
Community
  • 1
  • 1
M.M
  • 138,810
  • 21
  • 208
  • 365
  • If you still have trouble then it would be helpful to update your post to show the declaration of `innerAsk` – M.M Jun 04 '14 at 03:03
  • I did it like this: "void (*staticInnerAskPtr)(PortManager*) = staticInnerAsk; QFuture f = QtConcurrent::run(staticInnerAskPtr, this);" where staticInnerAsk(*) just calls *->innerAsk() but your version removes all the errors too and it's simpler... thank you. :) – smsware Jun 04 '14 at 03:09