PDA

View Full Version : blockingMap: no matching function for call to `(QList<QString>&, <unknown type>)`



qweide
15th August 2009, 14:28
Hi guys,

I am trying to use the Thread functions like in the map example.

I needed the scale function to access the ui, so I changed it in the cpp file to this:


QString MainWindow::scale(const QString &filename)
{
...
}

This appearently required me to add it to the header file. I did it like this:

...
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
QString scale(const QString &filename);
...

The call remains
QtConcurrent::blockingMapped(images, scale);

The error message I receive is:

mainwindow.cpp:85: error: no matching function for call to `blockingMapped(QList<QString>&, <unknown type>)'

Why doesn't he recognize the function anymore? :(

Any help is greatly appreciated :).

qweide

e8johan
15th August 2009, 17:05
I think that your scale function either has to be declared outside the class, or be static.

qweide
15th August 2009, 17:14
Hi,

Thanks for your ideas :).
I can't make it static in my opinion as I want to access the UI from there :/.
I'll try to put it to a separate class, but I think that it would kill my access to the UI as well, wouldn't it?

qweide

e8johan
15th August 2009, 17:17
Not a separate class, outside a class. Either way you can access it from other places. A static method does not have a "this" pointer, and when calling the function from QtConcurrent, without an object, there is no this pointer (think about it, it is obvious once you've wrapped your head around it... :-))

qweide
15th August 2009, 17:25
Hi,

I don't really get what you mean :(.
I attach my little project and would appreciate a lot if you had time to give it a quick look.

Thanks in advance,
qweide

p.s. I come from the Java island :D.

e8johan
15th August 2009, 17:38
I have not looked at your project, but let me put it like this:

What happens when you call something in QtConcurrent? The function that you pass to it is called repeatedly.

How do you call scaled? You use an object instance, inst, and use the -> or . operator: inst->scale( ... ).

The QtConcurrent framework does not have access to this. scale is simply a pointer to the scale function, not a specific class instance.

Thus, scale cannot be an ordinary class function. It must be able to execute without a this pointer. By making scale static, you can call it either as MyClass::scale( ... ), or inst->scale( ... ). Which is good enough for QtConcurrent (and probably your needs as well).

wysota
15th August 2009, 18:27
I can't make it static in my opinion as I want to access the UI from there :/.
I'll try to put it to a separate class, but I think that it would kill my access to the UI as well, wouldn't it?

You can't access the UI from threads anyway...

numbat
16th August 2009, 09:03
You can bind the this pointer to create a unary function object (a function object that takes one argument):


#include <QtConcurrentMap>
#include <functional>

QString MainWindow::scale(QString str)
{
qDebug() << str;
return str;
}


MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QStringList images;
images << "One" << "Two" << "Three";

QtConcurrent::blockingMapped(images, std::bind1st(std::mem_fun(&MainWindow::scale), this));
}