QtConcurrent ::在mac os上运行lambda不提供匹配功能

时间:2013-10-10 12:05:52

标签: c++ macos lambda qt4

我有以下示例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的MacO上,我收到以下错误消息:

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上? 提前谢谢

1 个答案:

答案 0 :(得分:3)

对于Clang您可以使用此解决方法:

QtConcurrent::run(std::function<void()>( []() { } ));

这也适用于捕获列表和其他参数:

QFuture<int> future = QtConcurrent::run(std::function<int(int)>( [&](int a) { return a; } ), 10);