Error connecting lambda function to QProcess :: error
In the following code, I want to connect a lambda function to QProcess :: error:
void Updater::start() {
QProcess process;
QObject::connect(&process, &QProcess::error, [=] (QProcess::ProcessError error) {
qWarning() << "error " << error;
});
process.start("MyProgram");
process.waitForFinished();
}
But I am getting weird error:
error: there is no corresponding function to call "Updater :: connect (QProcess * [unresolved overloaded function type], Updater :: start (): :) '});
What am I doing wrong here? The code executes inside a method of the class derived from the QObject. The project is set to work with C ++ 11.
I am using Qt 5.3.1 on Linux x32 with gcc 4.9.2
source to share
The problem is that it QProcess
has a different method error()
, so the compiler just doesn't know which method is using. If you want to deal with overloaded methods, you should use the following:
QProcess process;
connect(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>
(&QProcess::error), [=](QProcess::ProcessError pError) {
qWarning() << "error " << pError;
});
process.start("MyProgram");
process.waitForFinished();
Yes, it looks ugly, but there is no other way (just the old syntax?).
This special line tells the compiler what you want to use void QProcess::error(QProcess::ProcessError error)
, so now there is no ambiguity
source to share