I'm having trouble using QtConcurrent::map with boost::bind. The Qt documentation gives a brief example using a QImage, but we need to do something a little different. After searching and trying many different things, I thought I'd start with the most basic example.
#include <boost/bind.hpp>
#include <qtconcurrentmap.h>
void doSomething(int value)
{
// Want to open a file corresponding to a QString here,
// but how does it get passed in?
}
int main(int argc, char *argv[])
{
for (int i=0; i<100; i++)
{
filename.
append(QString::number(i
));
filename.append(".dat");
filenames << filename;
}
QFuture<void> future = QtConcurrent::map(filenames, boost::bind(doSomething, 50));
return 0;
}
#include <boost/bind.hpp>
#include <qtconcurrentmap.h>
void doSomething(int value)
{
// Want to open a file corresponding to a QString here,
// but how does it get passed in?
}
int main(int argc, char *argv[])
{
QStringList filenames;
for (int i=0; i<100; i++)
{
QString filename("f");
filename.append(QString::number(i));
filename.append(".dat");
filenames << filename;
}
QFuture<void> future = QtConcurrent::map(filenames, boost::bind(doSomething, 50));
return 0;
}
To copy to clipboard, switch view to plain text mode
This passes in the integer 50 to the doSomething function.
The Qt documentation gives an example that doesn't use boost:bind where it takes each item in the Sequence and calls a function:
{
image = image.scaled(100, 100);
}
QList<QImage> images = ...;
QFuture<void> future = QtConcurrent::map(images, scale);
void scale(QImage &image)
{
image = image.scaled(100, 100);
}
QList<QImage> images = ...;
QFuture<void> future = QtConcurrent::map(images, scale);
To copy to clipboard, switch view to plain text mode
In this case, scale is called with the object in the images list (a QImage). In order to pass additional arguments, the documentation says we can combine QtConcurrent::map with boost::bind.
Can somebody tell me how to implement a function that includes the object in the list (QString in my case) with additional parameters?
I wanted this to work:
void doSomething
(QString filename,
int value
) {
}
void doSomething(QString filename, int value)
{
}
To copy to clipboard, switch view to plain text mode
but of course it doesn't even compile, indicating that
`void (*)(QString, int)' is not a class, struct, or union type
Bookmarks