View Full Version : Simple question about QtConcurrent
vcp
14th September 2009, 19:18
Hi,
I've the following question:
Why don't we be able to use a member function jointly with QtConcurrent or QThread? Why must be a standalone function?
Thanks
wysota
15th September 2009, 06:23
It can be a member function as well but it has to be a member function of a class that is carried in the container passed to QtConcurrent. Otherwise than that only static member functions and non-member functions may be used. This is caused by the fact that it is not possible to specify a "pointer to a function of any class" in C++.
vcp
15th September 2009, 14:44
Hi Wysota,
Thanks a lot, now I understand.
Bye
caduel
15th September 2009, 17:08
I am not sure if I understood the OP's question correctly.
You can use member functions for some things, e.g. with QtConcurrent::mapped, if you wrap them with Boost.Bind or something similar.
Example from Qt docs:
QList<QImage> images = ...;
QFuture<QImage> thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation));
HTH
vcp
15th September 2009, 18:03
Hi Caduel,
yes something as:
class TEST
{
public:
TESTE();
void funct();
};
TESTE test;
QList<QImage> images = ...;
QFuture<QImage> thumbnails = QtConcurrent::mapped(images, test.funct(&QImage::scaledToWidth, 100 Qt::SmoothTransformation));
Now I understand that isn't possible. I must be use static functions for example.
Like the Wysota explained me
caduel
15th September 2009, 19:58
your example is confusing... a function returning void does not make sense with "mapping".
class TEST
{
public:
TESTE();
QImage funct(const QString&);
};
TESTE test;
QLis<QString> files = ...;
QFuture<QImage> pics = QtConcurrent::mapped(files, boost::bind(&TEST::func, &test));
something like that should work. (Haven't tried it.)
vcp
15th September 2009, 21:14
Sorry,
I know about this.
Your example this ok.
Thanks for your help
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.