简体   繁体   English

类型'void(ClassName ::)(QString&)'的参数与'void(ClassName :: *)(QString&)'不匹配

[英]argument of type 'void (ClassName::)(QString&)' does not match 'void (ClassName::*)(QString&)'

Im trying to use Qt's qtconcurrentmap to process some images and I'm getting the following error 我正在尝试使用Qt的qtconcurrentmap处理一些图像,但出现以下错误

argument of type 'void (ClassName::)(QString&)' does not match 'void (ClassName::*)(QString&)

I'm also getting 我也越来越

/Library/Frameworks/QtCore.framework/Headers/qtconcurrentmapkernel.h:: 
In member function 'bool QtConcurrent::MapKernel<Iterator, MapFunctor>::runIteration(Iterator, int, void*) 
[with Iterator = QList<QString>::iterator, MapFunctor = void (ClassName::*)(QString&)]':


/Library/Frameworks/QtCore.framework/Headers/qtconcurrentmapkernel.h:73: 
error: must use '.*' or '->*' to call pointer-to-member function in 
'((QtConcurrent::MapKernel<QList<QString>::iterator, void (ClassName::*)(QString&)>*)this)->QtConcurrent::MapKernel<QList<QString>::iterator, void (ClassName::*)(QString&)>::map (...)'

This is my code 这是我的代码

void ClassName::processImage(QString &f)
{

    Image image;
        image.read(qPrintable(f));
        try {
            //Apply effects on an Image
        } catch ( Magick::Exception & error) {
            // Displaying any possible errors on the text browser
            ui->textBrowser_error->setText(error.what());

        }
}



void ClassName::processAll() {

    foreach (QFileInfo f, list)
     {      QString str(f.absoluteFilePath());
            QList<QString> listof;
            listof.append(str);
     }


    QFuture<void> future = QtConcurrent::map(listof, processImage);
}

Any Ideas? 有任何想法吗?

Two things here. 这里有两件事。 First, the variable listof is declared inside the foreach loop, so it may not be visible at the point of creating future . 首先,变量listof是在foreach循环内声明的,因此在创建future时可能不可见。 Second, you should use &ClassName::processImage as the second parameter to QtConcurrent::map() . 其次,您应该使用&ClassName::processImage作为QtConcurrent::map()的第二个参数。

UPDATE : 更新

Looking at the documentation, it seems you need to write the call to create the map this way: 查看文档,看来您需要编写调用以这种方式创建地图:

QFuture<void> future = QtConcurrent::map(listof, boost::bind(&ClassName::processImage, this));

(you have to use boost.bind to convert a member function into a normal function, that is what map expect as the second argument). (您必须使用boost.bind将成员函数转换为普通函数,这就是map期望的第二个参数)。

我认为它采用的是功能而不是功能地址。

QFuture<void> future = QtConcurrent::map(listof, &ClassName::processImage);

About the second error: You can't pass a non-static member function like this. 关于第二个错误:您不能像这样传递非静态成员函数。 map() wouldn't know which object to call it on (which must be of type ClassName). map()不知道要调用哪个对象(该对象必须是ClassName类型)。

From QtConcurrentMap docs: 从QtConcurrentMap文档:

QtConcurrent::map(), QtConcurrent::mapped(), and QtConcurrent::mappedReduced() accept pointers to member functions. QtConcurrent :: map(),QtConcurrent :: mapped()和QtConcurrent :: mappedReduced()接受指向成员函数的指针。 The member function class type must match the type stored in the sequence: " 成员函数类的类型必须与序列中存储的类型匹配:

You pass a QString list, but the member function is from ClassName. 您传递一个QString列表,但成员函数来自ClassName。 You can achieve something like this with boost::bind (and probably also with some mem_fun/bind1st-fu from the STL): 您可以使用boost :: bind(也可以使用STL的mem_fun / bind1st-fu)实现类似的功能:

...map( listof, boost::bind( &ClassName::processImage, this, _1 ) );

Still this won't work as you can't call QTextEdit::setText() from other threads than the UI thread. 但这仍然行不通,因为您无法从UI线程以外的其他线程调用QTextEdit :: setText()。

Also, it should be processImage(const QString&) instead of processImage(QString&). 另外,它应该是processImage(const QString&)而不是processImage(QString&)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从QString *转换为QString& - Conversion from QString* to QString& QString&和QString&之间有什么区别吗? - Is there any difference between QString& and QString &? QString&QString :: operator =(const QByteArray&)&#39;是私有的 - QString& QString::operator=(const QByteArray&)' is private 错误:没有用于调用“QLabel::text(QString&amp;)”的匹配函数 - Error: no matching function for call to 'QLabel::text(QString&)' 错误:类型为“ void *(Thread ::)(void *)”的参数与“ void *(*)(void *)”不匹配 - error: argument of type ‘void* (Thread::)(void*)’ does not match ‘void* (*)(void*)’ 类型&#39;void *(...)(void *)&#39;的参数与&#39;void *(*)(void *) - argument of type 'void* (…)(void*)' does not match 'void* (*)(void*) 将QString转换为const void * - Convert QString to const void* 无法从类型void *(classname::)()转换为类型void *(*)(void *) - cannot convert from type void*(classname::) () to type void*(*)(void*) 为什么const QString&param返回错误的const char *指向数据的指针 - Why const QString& param return bad const char* pointer to data 没有用于调用 &#39;std::basic_ifstream 的匹配函数<char> ::basic_ifstream(QString&amp;)&#39; - no matching function for call to ‘std::basic_ifstream<char>::basic_ifstream(QString&)’
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM