PDA

View Full Version : QtConcurrent, Unresolved Overloaded Function Type



lynchkp
23rd November 2010, 21:46
Hey everyone,

I'm trying to incorportate QtConcurrent into one of my classes, and I'm starting simple with it:



#include "coredata.h"

CoreData::CoreData()
{

}

void CoreData::afunc()
{

}

void CoreData::threaded()
{
QFuture<void> future = QtConcurrent::run(afunc);
}


This results in an error:
error: no matching function for call to 'run(<unresolved overloaded function type>)'

I've looked through the Qt Documentation, and since it is all within the main() function, I don't know how it works within a class. I have a feeling I'm missing something simple, but I'm relatively new to C++ and the solution is escaping me.

Thanks in advance!!

wysota
23rd November 2010, 23:39
You don't have a "afunc" function. You only have a CoreData::afunc method.


QFuture<void> future = QtConcurrent::run(this, &CoreData::afunc);

lynchkp
24th November 2010, 05:56
Thank you for the help; I implemented that in my code and it works great. However, after looking through the documentation I believe the QtConcurrent::map would be better since it allows control over the timing, which I need.

I have a vector "idxvec" that has n elements, going from 0 to n. I'd like to implement the function like this:



vector<qint32> idxvec(nregions);

for (idx = 0; idx < nregions; idx++)
idxvec[idx] = idx;

QtConcurrent::map(idxvec,this,&CoreData::runCorrelation);


However this doesn't compile. I apologize for all these questions, the documentation is really sparse about this :(

Thanks!

tbscope
24th November 2010, 06:30
The prototype of the function you want to use is:


QFuture<void> QtConcurrent::map ( Iterator begin, Iterator end, MapFunction function )

As you can see, using "this" for "Iterator end" does not work, neither does the first parameter work.

lynchkp
24th November 2010, 07:21
I'm trying to implement that prototype, however the problem I'm having is that I cannot use my class method CoreData::runCorrelation as the function. Do I need to use boost::bind to attach the class method to the this pointer?

Thanks,

wysota
24th November 2010, 09:38
Can you make your runCorrelation method static? If yes then do so.