我正在使用c ++ 11和QT 5.12。
我尝试将QProcess :: finished(int,QProcess :: ExitCode)信号连接到lambda,但使用代码
QProcess PlayerProcess;
connect(PlayerProcess, &QProcess::finished,
[=](int exitCode, QProcess::ExitStatus exitStatus)
{
// Function body
}
编译器说
../Qt/5.12.1/gcc_64/include/QtCore/qobject.h:300:13: note: no known conversion for argument 1 from ‘QProcess’ to ‘const Object* {aka const QProcess*}’
../Qt/5.12.1/gcc_64/include/QtCore/qobject.h:308:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)
connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
^~~~~~~
../Qt/5.12.1/gcc_64/include/QtCore/qobject.h:308:13: note: template argument deduction/substitution failed:
../Launcher/mainwindow.cpp:184:9: note: candidate expects 5 arguments, 3 provided
);
仔细检查一下,我发现的唯一相关问题是MainWindow类不是从QObject派生的(但是我的MainWindow是从QMainWindow派生的,而QMainWindow是从QWidget派生的),或者编译器无法解析重载的QProcess ::完成的信号(可以是(int)或(int,QProcess :: ExitCode),但是为此,我尝试了两个可以找到的快速修复程序:
void (QProcess::* mySignal)(int, QProcess::ExitStatus) = &QProcess::finished;
auto mySignal2 = QOverload<int,QProcess::ExitStatus>::of(&QProcess::finished);
但同时使用这两个编译器错误不会改变。
我在这里想念什么?
谢谢。
答案 0 :(得分:1)
正如@ymoreau所说,QObject :: connect函数需要参数作为指针,所以我用&PlayerProcess更改了连接的第一个参数。
然后,使用两个显式重载之一解决了重载QProcess :: finished问题。