PDA

View Full Version : QtConcurrent::run Help(SOLVED)



AwDogsgo2Heaven
9th July 2009, 02:15
This is probaly more of a C++ question than a Qt question. But nevertheless it involves the QtConcurrent::run function.

My question is, what is the proper way to pass a function into QtConcurrent::run? I want to pass a member function that is inherited specifically, but no matter what I do it throws a long list of errors saying im not using the function correctly. Also the function has parameter, one of which is a pointer, is this okay?

I've read the documentation and maybe I've missed something. But it doesn't seem to be very detailed on what is allowed and not and maybe I should just know.
If anyone can give me any insight thanks.

nish
9th July 2009, 02:21
can you show the code? may be its the case of missing & or class qualifier

AwDogsgo2Heaven
9th July 2009, 02:36
I dont have the code on me. But here is a pretty much same example:

I tried doing this -

QFuture<void> future = QtConcurrent::run(&Scope::function, parameter);

The scope was of the inherited class and the parameter was a pointer to an object.

nish
9th July 2009, 02:54
i think the docs read that you have to pass an object or the pointer to call a member function...


Additional API Features
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.
For example, calling QString::split() (a const member function) in a separate thread is done like this:
// call 'QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const' in a separate thread
QString string = ...;
QFuture<QStringList> future = QtConcurrent::run(string, &QString::split, QString(", "), QString::KeepEmptyParts, Qt::CaseSensitive);
...
QStringList result = future.result();
Calling a non-const member function is done like this:
// call 'void QImage::invertPixels(InvertMode mode)' in a separate thread
QImage image = ...;
QFuture<void> future = QtConcurrent::run(image, &QImage::invertPixels, QImage::InvertRgba);
...
future.waitForFinished();
// At this point, the pixels in 'image' have been inverted