1
votes

I'm using c++11, and QT 5.12.
I'm trying to connect to the QProcess::finished(int,QProcess::ExitCode) signal to a lambda, but using the code

QProcess PlayerProcess;
connect(PlayerProcess, &QProcess::finished,
[=](int exitCode, QProcess::ExitStatus exitStatus)
{
 //  Function body
}

the compiler says

../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
         );

Googling a bit, the only related problems I could find were that the MainWindow class wasn't deriving from a QObject (but my MainWindow derives from QMainWindow that derives from QWidget), or that the compiler couldn't resolve the overloaded QProcess::finished signal (that could be either (int) or (int,QProcess::ExitCode), but for this I tried both the quickfixes I could find:

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

but using both the compiler error doesn't change.

What did I miss here?

Thanks in advance.

1
QObject::connect function takes pointers in parameters, not values/references. You need to pass &PlayerProcess in your code.ymoreau
Oh. That solved, thanks. I can't say I feel stupid because I didn't know that it needed a pointer :PMewster

1 Answers

1
votes

As @ymoreau said, the QObject::connect function needs parameters as pointers, so i changed the connect's first parameter with a &PlayerProcess.

Then, the overloading QProcess::finished problem was solved using one of the two explicit overload.