QtConcurrent::run with lambda on mac os 没有提供匹配函数
QtConcurrent::run with lambda on mac os gives no matching function
我有以下示例 Qt 控制台应用程序
#include <QCoreApplication>
#include <QtCore>
#include <QFuture>
#include <iostream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
auto lambda = [](){
std::cout << "I will do some totally independent stuff here" << std::endl;
};
QFuture<void> future = QtConcurrent::run( lambda );
//i will do some concurrent work here...
future.waitForFinished();
return a.exec();
}
使用此 .pro 文件
QT += core
QT -= gui
TARGET = demo
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.8
QMAKE_CXXFLAGS += -funroll-loops -msse4.1 -O3
QMAKE_LFLAGS += -stdlib=libc++ -mmacosx-version-min=10.8
它在具有Visual C++ 2012和Qt 4.8.5的Windows上编译并运行。在使用带有给定.pro文件和相同Qt版本的最新clang的MacOS上,我收到以下错误消息:
13:57:18: Führe Schritte für Projekt demo aus...
13:57:18: Unveränderte Konfiguration, qmake-Schritt wird übersprungen.
13:57:18: Starte "/usr/bin/make"
clang++ -c -pipe -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.8 -funroll-loops -msse4.1 -O3 -g -gdwarf-2 -arch x86_64 -Wall -W -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Qt4.8/mkspecs/unsupported/macx-clang -I../demo -I/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/usr/include/QtCore -I/usr/include -I. -I../demo -I. -F/Library/Frameworks -o main.o ../demo/main.cpp
../demo/main.cpp:16:28: error: no matching function for call to 'run'
QFuture<void> future = QtConcurrent::run( lambda );
^~~~~~~~~~~~~~~~~
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:72:12: note: candidate template ignored: failed template argument deduction
QFuture<T> run(T (*functionPointer)())
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:154:47: note: candidate template ignored: substitution failure [with FunctionObject = <lambda at ../demo/main.cpp:12:19>]: no type named 'result_type' in '<lambda at ../demo/main.cpp:12:19>'
QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject)
~~~~~~~~~~~ ^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:185:47: note: candidate template ignored: failed template argument deduction
QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:77:12: note: candidate function template not viable: requires 2 arguments, but 1 was provided
QFuture<T> run(T (*functionPointer)(Param1), const Arg1 &arg1)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:82:12: note: candidate function template not viable: requires 3 arguments, but 1 was provided
QFuture<T> run(T (*functionPointer)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:87:12: note: candidate function template not viable: requires 4 arguments, but 1 was provided
QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:92:12: note: candidate function template not viable: requires 5 arguments, but 1 was provided
QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:97:12: note: candidate function template not viable: requires 6 arguments, but 1 was provided
QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:159:47: note: candidate function template not viable: requires 2 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:164:47: note: candidate function template not viable: requires 3 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:169:47: note: candidate function template not viable: requires 4 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:174:47: note: candidate function template not viable: requires 5 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:179:47: note: candidate function template not viable: requires 6 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:190:47: note: candidate function template not viable: requires 2 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:195:47: note: candidate function template not viable: requires 3 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:200:47: note: candidate function template not viable: requires 4 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:205:47: note: candidate function template not viable: requires 5 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:210:47: note: candidate function template not viable: requires 6 arguments, but 1 was provided
QFuture<typename FunctionObject::result_type> run(FunctionObject *functionObject, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:216:12: note: candidate function template not viable: requires 2 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)())
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:221:12: note: candidate function template not viable: requires 3 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1), const Arg1 &arg1)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:226:12: note: candidate function template not viable: requires 4 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:231:12: note: candidate function template not viable: requires 5 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:236:12: note: candidate function template not viable: requires 6 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:241:12: note: candidate function template not viable: requires 7 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:247:12: note: candidate function template not viable: requires 2 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)() const)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:252:12: note: candidate function template not viable: requires 3 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1) const, const Arg1 &arg1)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:257:12: note: candidate function template not viable: requires 4 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2) const, const Arg1 &arg1, const Arg2 &arg2)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:262:12: note: candidate function template not viable: requires 5 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:267:12: note: candidate function template not viable: requires 6 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3, Param4) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:272:12: note: candidate function template not viable: requires 7 arguments, but 1 was provided
QFuture<T> run(const Class &object, T (Class::*fn)(Param1, Param2, Param3, Param4, Param5) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:278:12: note: candidate function template not viable: requires 2 arguments, but 1 was provided
QFuture<T> run(Class *object, T (Class::*fn)())
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:283:12: note: candidate function template not viable: requires 3 arguments, but 1 was provided
QFuture<T> run(Class *object, T (Class::*fn)(Param1), const Arg1 &arg1)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:288:12: note: candidate function template not viable: requires 4 arguments, but 1 was provided
QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:293:12: note: candidate function template not viable: requires 5 arguments, but 1 was provided
QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:298:12: note: candidate function template not viable: requires 6 arguments, but 1 was provided
QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:303:12: note: candidate function template not viable: requires 7 arguments, but 1 was provided
QFuture<T> run(Class *object, T (Class::*fn)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:309:12: note: candidate function template not viable: requires 2 arguments, but 1 was provided
QFuture<T> run(const Class *object, T (Class::*fn)() const)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:314:12: note: candidate function template not viable: requires 3 arguments, but 1 was provided
QFuture<T> run(const Class *object, T (Class::*fn)(Param1) const, const Arg1 &arg1)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:319:12: note: candidate function template not viable: requires 4 arguments, but 1 was provided
QFuture<T> run(const Class *object, T (Class::*fn)(Param1, Param2) const, const Arg1 &arg1, const Arg2 &arg2)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:324:12: note: candidate function template not viable: requires 5 arguments, but 1 was provided
QFuture<T> run(const Class *object, T (Class::*fn)(Param1, Param2, Param3) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:329:12: note: candidate function template not viable: requires 6 arguments, but 1 was provided
QFuture<T> run(const Class *object, T (Class::*fn)(Param1, Param2, Param3, Param4) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
^
/Library/Frameworks/QtCore.framework/Versions/4/Headers/qtconcurrentrun.h:334:12: note: candidate function template not viable: requires 7 arguments, but 1 was provided
QFuture<T> run(const Class *object, T (Class::*fn)(Param1, Param2, Param3, Param4, Param5) const, const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
^
1 error generated.
make: *** [main.o] Error 1
13:57:20: Der Prozess "/usr/bin/make" wurde mit dem Rückgabewert 2 beendet.
Fehler beim Erstellen/Deployment des Projekts demo(Kit: Desktop)
Bei der Ausführung von Schritt 'Make'
13:57:20: Verstrichene Zeit: 00:01.
谁能解释为什么此错误发生在 mac OS 上?提前谢谢你
对于 Clang 您可以使用以下解决方法:
QtConcurrent::run(std::function<void()>( []() { } ));
这也适用于捕获列表和其他参数:
QFuture<int> future = QtConcurrent::run(std::function<int(int)>( [&](int a) { return a; } ), 10);
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 对RValue对象调用的LValue ref限定成员函数
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 谷歌测试编译错误 Os X:函数式转换从"int"到"internal::FloatingEq2Matcher"的模糊转换<float>
- 基类 C++14 模板函数在 Mac OS 上的 clang 中不可见(递归模板)
- GDB 7.5 (OS X):无法从库函数访问源代码
- 在Matlab中使用OS X编译/混合imrender函数时出错
- QtConcurrent::run with lambda on mac os 没有提供匹配函数
- 如何使用Mac OS X音频API函数
- 如何理解函数 ostream&operator<< (ostream& os, const unsigned char* s)
- 在Mac OS X上共享一个c++库,这样我就可以在mySQL中添加用户定义的函数
- 迷你OS -III定时器回调函数没有被调用
- 链接到Mac OS X上的静态c++库:不调用库中的全局对象构造函数
- GNU gdb无法进入模板函数(OS X Mavericks)