我使用的是c++11和QT5.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来自从QWidget派生的QMainWindow ),或者编译器无法解决重载的QProcess::finished信号(可以是(int)或(int,QProcess::ExitCode),但为此,我尝试了我可以找到的两个快速修复:
void (QProcess::* mySignal)(int, QProcess::ExitStatus) = &QProcess::finished;
auto mySignal2 = QOverload<int,QProcess::ExitStatus>::of(&QProcess::finished);但是,使用这两种编译器错误都不会改变。
我错过了什么?
提前谢谢。
发布于 2019-02-19 08:23:35
正如@ymoreau所述,QObject::connect函数需要参数作为指针,因此我用一个&PlayerProcess更改了connect的第一个参数。
然后,使用两个显式重载之一解决了过载QProcess::finished问题。
https://stackoverflow.com/questions/54761515
复制相似问题