QT,无法将QProcess :: finished(int,QProcess :: ExitStatus)信号绑定到lambda

问题描述 投票:1回答:1

我正在使用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派生自QWidget),或者编译器无法解析重载的QProcess :: finished signal(可以是(int)或(int,QProcess :: ExitCode),但为此我尝试了两个我能找到的快速修正:

void  (QProcess::* mySignal)(int, QProcess::ExitStatus) = &QProcess::finished;
auto mySignal2 = QOverload<int,QProcess::ExitStatus>::of(&QProcess::finished);

但是使用两者编译器错误都不会改变。

我在这里想念的是什么?

提前致谢。

qt signals qprocess
1个回答
1
投票

正如@ymoreau所说,QObject :: connect函数需要参数作为指针,所以我用一个&PlayerProcess改变了connect的第一个参数。

然后,使用两个显式重载之一解决了重载QProcess :: finished问题。

© www.soinside.com 2019 - 2024. All rights reserved.