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
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
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... :-))
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.
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).
You can bind the this pointer to create a unary function object (a function object that takes one argument):
Qt Code:
#include <QtConcurrentMap> #include <functional> { qDebug() << str; return str; } { QStringList images; images << "One" << "Two" << "Three"; QtConcurrent::blockingMapped(images, std::bind1st(std::mem_fun(&MainWindow::scale), this)); }To copy to clipboard, switch view to plain text mode
Bookmarks