将lambda函数连接到QProcess :: error时出错 [英] Error while connecting lambda function to QProcess::error

查看:104
本文介绍了将lambda函数连接到QProcess :: error时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我想将lambda函数连接到QProcess ::错误信号:

In following code I want to connect lambda function to QProcess::error signal:

void Updater::start() {
    QProcess process;
    QObject::connect(&process, &QProcess::error, [=] (QProcess::ProcessError error) {
        qWarning() << "error " << error;
    });
    process.start("MyProgram");
    process.waitForFinished();
}

但我遇到奇怪的错误:


错误:没有匹配的函数调用'Updater :: connect(QProcess *
[未解析的重载函数类型],
Updater :: start(): :)'});

error: no matching function for call to 'Updater::connect(QProcess* [unresolved overloaded function type], Updater::start()::)' });

我在这里做错了什么?该代码执行从QObject派生的类的内部方法。该项目配置为可与c ++ 11一起使用。

What I do wrong here? The code executes inside method of class derived from QObject. The project configured to work with c++11.

我在Linux x32上使用Qt 5.3.1和gcc 4.9.2

I use Qt 5.3.1 on Linux x32 with gcc 4.9.2

推荐答案

问题是 QProcess 还有另一个 error() 方法,因此编译器只是不知道使用哪种方法。如果要处理重载方法,则应使用下一个:

Problem is that the QProcess has another error() method, so compiler just doesn't know which method use. If you want to deal with overloaded methods, you should use next:

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 another way (only old syntax?).

此特殊行告诉编译器您要使用 void QProcess :: error(QProcess :: ProcessError error),所以现在没有任何歧义

This special line tells compiler that you want to use void QProcess::error(QProcess::ProcessError error), so now there is no any ambiguity

您可以在此处找到更多信息

这篇关于将lambda函数连接到QProcess :: error时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆