QtConcurrent, Unresolved Overloaded Function Type
Hey everyone,
I'm trying to incorportate QtConcurrent into one of my classes, and I'm starting simple with it:
Code:
#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!!
Re: QtConcurrent, Unresolved Overloaded Function Type
You don't have a "afunc" function. You only have a CoreData::afunc method.
Code:
QFuture<void> future = QtConcurrent::run(this, &CoreData::afunc);
Re: QtConcurrent, Unresolved Overloaded Function Type
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:
Code:
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!
Re: QtConcurrent, Unresolved Overloaded Function Type
The prototype of the function you want to use is:
Quote:
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.
Re: QtConcurrent, Unresolved Overloaded Function Type
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,
Re: QtConcurrent, Unresolved Overloaded Function Type
Can you make your runCorrelation method static? If yes then do so.