OzQTNoob
22nd November 2012, 02:39
Hi all experienced types,
I have a couple of questions about using QtConcurrent. So I spent days and days just trying to get something to actually run in another thread (not a simple QImage example - so sick of seeing those) but one where I needed a member function from one of my own classes. A have read and read various posts, articles, TFM etc and find it very esoteric to be be truthful. I am not bagging the various sources just my lack of C++ and Qt experience. So firstly,
1) if I instantiate and object in my code;
SomeClass *myClass = new SomeClass(arg1, arg2,..,this)
and then use QtConcurrent to start a trhead;
QFuture<T> = QtConcurrent::run(myClass,&SomeClass::myFunction, newarg1, newarg2) for example. Is QtConcurrent::run using the myClass object internal variables when it runs myFunction (and assuming myFunction requires these but not through the call to the function)? e.g. I have a private variable arg1 which was set in the constructor and which myFunction uses as well.
2) If I want to use QtConcurrent::mapped (which still fails me, and yes the documentation I am sure is fantastic but confusing to me) is the only way for me to get it to use a function that has multiple arguments to use boost::bind or the other suggested one? Otherwise it seems, and correct me if I am wrong, that I am only able to run a function that ever takes a singular input (which seems really, really limiting) EDIT: found this link on the wiki but not really what I was afterhttp://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMapped-Other-Object-Member-Function-Operator
3) Can anyone tell me what the error message here is referring to. I suspect its something simple but I don't understand what it is that I have done wrong;
C:\Qt_projects\DrillDown\DrillDown\feature_finder. cpp:582: error: C2679: binary '=' : no operator found which takes a right-hand operand of type 'QFuture<void>' (or there is no acceptable conversion)
c:\qtsdk\desktop\qt\4.8.1\msvc2010\include\qtcore\ qvector.h(125): could be 'QVector<T> &QVector<T>::operator =(const QVector<T> &)'
with
[
T=QVector<QVector<QVector<double>>>
]
c:\qtsdk\desktop\qt\4.8.1\msvc2010\include\qtcore\ qvector.h(127): or 'QVector<T> QVector<T>::operator =(QVector<T> &&)'
with
[
T=QVector<QVector<QVector<double>>>
]
while trying to match the argument list '(QVector<T>, QFuture<void>)'
with
[
T=QVector<QVector<QVector<double>>>
]
The offending line of code is below and is called (or not in this case) in a member function of the feature_finder class. Extraction is also a member function of feature_finder, albeit one I have had to try and tweak down to a singular input argument.
QVector<QVector<QVector<QVector<double> > > > future;
future = QtConcurrent::mapped(spectrain,&feature_finder::Extraction);
I am more interested in knowing if anyone has seen the same error can let me know what it means (I understand that it is saying that the right hand side returns a future<void> but why?
I have tried what seems like a million variants on the above usage and f&*ked if I can get it to work in any capacity what so ever (go easy on me I am a NOOB)
Cheers
Oz
I have a couple of questions about using QtConcurrent. So I spent days and days just trying to get something to actually run in another thread (not a simple QImage example - so sick of seeing those) but one where I needed a member function from one of my own classes. A have read and read various posts, articles, TFM etc and find it very esoteric to be be truthful. I am not bagging the various sources just my lack of C++ and Qt experience. So firstly,
1) if I instantiate and object in my code;
SomeClass *myClass = new SomeClass(arg1, arg2,..,this)
and then use QtConcurrent to start a trhead;
QFuture<T> = QtConcurrent::run(myClass,&SomeClass::myFunction, newarg1, newarg2) for example. Is QtConcurrent::run using the myClass object internal variables when it runs myFunction (and assuming myFunction requires these but not through the call to the function)? e.g. I have a private variable arg1 which was set in the constructor and which myFunction uses as well.
2) If I want to use QtConcurrent::mapped (which still fails me, and yes the documentation I am sure is fantastic but confusing to me) is the only way for me to get it to use a function that has multiple arguments to use boost::bind or the other suggested one? Otherwise it seems, and correct me if I am wrong, that I am only able to run a function that ever takes a singular input (which seems really, really limiting) EDIT: found this link on the wiki but not really what I was afterhttp://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMapped-Other-Object-Member-Function-Operator
3) Can anyone tell me what the error message here is referring to. I suspect its something simple but I don't understand what it is that I have done wrong;
C:\Qt_projects\DrillDown\DrillDown\feature_finder. cpp:582: error: C2679: binary '=' : no operator found which takes a right-hand operand of type 'QFuture<void>' (or there is no acceptable conversion)
c:\qtsdk\desktop\qt\4.8.1\msvc2010\include\qtcore\ qvector.h(125): could be 'QVector<T> &QVector<T>::operator =(const QVector<T> &)'
with
[
T=QVector<QVector<QVector<double>>>
]
c:\qtsdk\desktop\qt\4.8.1\msvc2010\include\qtcore\ qvector.h(127): or 'QVector<T> QVector<T>::operator =(QVector<T> &&)'
with
[
T=QVector<QVector<QVector<double>>>
]
while trying to match the argument list '(QVector<T>, QFuture<void>)'
with
[
T=QVector<QVector<QVector<double>>>
]
The offending line of code is below and is called (or not in this case) in a member function of the feature_finder class. Extraction is also a member function of feature_finder, albeit one I have had to try and tweak down to a singular input argument.
QVector<QVector<QVector<QVector<double> > > > future;
future = QtConcurrent::mapped(spectrain,&feature_finder::Extraction);
I am more interested in knowing if anyone has seen the same error can let me know what it means (I understand that it is saying that the right hand side returns a future<void> but why?
I have tried what seems like a million variants on the above usage and f&*ked if I can get it to work in any capacity what so ever (go easy on me I am a NOOB)
Cheers
Oz